Results 1 to 7 of 7

Thread: [RESOLVED] Type Casting in VB

  1. #1

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    46

    Resolved [RESOLVED] Type Casting in VB

    I got a textbox which will accept a SIZE from the user.

    based on this SIZE, i wan to go through a FOR loop SIZE number of times. Do i need to perform type casting to convert the text into integer or can i just use the SIZE as the FOR loop parameter?

    Thks
    FT

  2. #2
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Type Casting in VB

    It is always a good idea to be explicit.. which means you would use CLng to convert the string to Long and use it in the For loop.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  3. #3

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    46

    Re: Type Casting in VB

    Quote Originally Posted by Shuja Ali
    It is always a good idea to be explicit.. which means you would use CLng to convert the string to Long and use it in the For loop.
    does that mean if i wan to have it as interger i use

    Dim charSize As Integer

    charSize = CInt(Text4)

    How comes it gives me a type mismatch error when i do the above? thks

  4. #4
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: Type Casting in VB

    Did you try it like this
    VB Code:
    1. Dim charSize As Integer
    2.  
    3. charSize = CInt(Text4.Text)
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  5. #5

  6. #6

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    46

    Re: Type Casting in VB

    Quote Originally Posted by bushmobile
    what's in your Textbox?
    i enter integer values into the textbox..

  7. #7

    Thread Starter
    Member
    Join Date
    May 2006
    Posts
    46

    Re: Type Casting in VB

    okies guys, thks alot, everything is working fine now.. i did not used

    Dim charSize As Integer

    charSize = CInt(Text4.Text)

    just now.. thks alot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width