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

#1 goms89   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


is it possible.? Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: how to append a integer into textbox?

#2 maj3091   User is offline

  • D.I.C Lover
  • member icon

Reputation: 330
  • View blog
  • Posts: 1,997
  • 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   User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,071
  • 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