2 Replies - 743 Views - Last Post: 03 September 2012 - 07:01 AM Rate Topic: -----

#1 goms89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-September 12

how to append a integer into textbox?

Posted 03 September 2012 - 12:02 AM

hi friends,

my problem is i am trying to append the integer with text box.

my code is,

j = Val(Text2.Text)

For i = Val(Text1.Text) To Val(Text3.Text)
m = i * j
Text4.Text = Val(m) & vbCrLf
Text4.Visible = True

Next i


here, i am trying to multiply the two text box(in numbers ) until the user specified.
text box1-> starting number like(3)(it should be increased (3 , 4,5,6)
text box2-> mulply number like(5)(3*5,4*5,5*5,6*5)
text box3-> ending number like(10)(3,4,5,6,7,8,9,10)
the text box 4 must show the following output

15
20
25
30
35
40
45
50


is it possible.? Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: how to append a integer into textbox?

#2 maj3091  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 300
  • View blog
  • Posts: 1,776
  • Joined: 26-March 09

Re: how to append a integer into textbox?

Posted 03 September 2012 - 01:43 AM

Set the output textbox multiline property to True, then use the following to add to the textbox.

textbox.text = textbox.text & "Your new string" & vbcrlf

Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 574
  • View blog
  • Posts: 2,989
  • Joined: 19-May 09

Re: how to append a integer into textbox?

Posted 03 September 2012 - 07:01 AM

Also, Val is a deprecated function that is used to convert a string to an integer, that is retained for backward compatibility with earlier versions. CInt is more precise, as it will return an error if the string contains alpha characters. For example, Val("123abc") returns "123", whereas CInt("123abc") returns an error.

Next, you have a problem because you are using Val to attempt to convert a value to a string. The correct function to do this is CStr. Unfortunately, your code works, because VB converts to a string behind the scenes as soon as you concatenate a VbCrLf to your m variable. I say unfortunately because it's to my mind unfortunate that VB puts up with this sort of thing, because it makes it hard to learn by doing.

In any case, you should use CStr(m) & VbCrLf instead in that place, and I would suggest that you use CInt in the other places you use Val.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1