Results 1 to 12 of 12

Thread: Integers in a textbox

  1. #1

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Integers in a textbox

    So basically in this database there are random numbers that are some times 4 characters long and sometimes 5 characters. I tried to make a replace function like this:

    VB Code:
    1. Private Sub Form_Load()
    2. On Error GoTo move_first
    3. Do
    4. If GIS.Value = "xxxx" Then
    5. GIS.Value = "R00000" & GIS.Value
    6. ElseIf GIS.Value = "xxxxx" Then
    7. GIS.Value = "R0000" & GIS.Value
    8. Me.Recordset.MoveNext
    9. End If
    10. Loop
    11. Exit Sub
    12. move_first:
    13. Me.Recordset.MoveFirst
    14. End Sub

    Anyways, this just hangs the program and forces me to do a ctrl + alt + break

    if anyone has any ideas, they are greatly appreciated

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  2. #2
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Integers in a textbox

    Would this work for you?

    GIS.Value = Format(GIS.Value, "R000000000")
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Integers in a textbox

    What kind of control is GIS?

  4. #4

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: Integers in a textbox

    textbox
    And I dont know about that format command, because if the value in gis ='s 4 digits then there has to be "R + 5 zeros" is the gis ='s 5 digits then it has to be "R + 4 zeros"

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Integers in a textbox

    Quote Originally Posted by cid
    textbox
    If GIS is a textbox, then your first problem is that textbox's don't have a Value property. They have Text property. GIS.Value itself should be throwing an error.

  6. #6

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: Integers in a textbox

    this is VBA(Sorry i should have clarified that)

    And I believe in vba a textbox has the value property. Correct me if im wrong though.

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Integers in a textbox

    Quote Originally Posted by cid
    this is VBA(Sorry i should have clarified that)

    And I believe in vba a textbox has the value property. Correct me if im wrong though.
    I believe you are correct. Having said that, however, if your post remained in ClassicVB, you would be getting other possible comments or solutions to your problem, with VB6 code, that wouldn't work (like mine) because you are using VBA.

    Therefore, I've moved this to Office Development.

  8. #8

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: Integers in a textbox

    ok, thanks... any other information on my problem would be helpful.
    Thanks guys.

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  9. #9
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Integers in a textbox

    Try a formula like this:

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim a As String, s As String
    5.   a = "124"
    6.   s = "R" & String$(10 - Len(a), "0") & a
    7.   MsgBox s & "  " & Len(s)
    8. End Sub

    You might want to adjust the number 10 to suite your needs. This uses 11 digits each time.

    EDIT: Just noticed the move. Hope VBA has the String$ command. I believe that it does, though.

  10. #10

    Thread Starter
    Fanatic Member cid's Avatar
    Join Date
    Nov 2002
    Location
    Fort Worth, Texas
    Posts
    854

    Re: Integers in a textbox

    im a little new but from looking at that code i gather...

    A is a set variable that is equal to 124, and s is a string that inserts R and 11 zeros infront of the variable a?

    I need to be able to insert "R0000" infront of a 5 digit number(random) and insert "R00000" infront of a 4 digit number. So I am not sure if your code will work with my needs.

    www.google.com - Pay Tribute.

    Always Listening To: Thrice

  11. #11
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Integers in a textbox

    you could add a function that will convert your input value to a string of 11 characters. Then in the _change event of the textbox call that function.

    Function Code
    VB Code:
    1. Function Cid(Value As String) As String
    2.  
    3. Const Prefix As String = "R0000000000"
    4.  
    5. Cid = Left(Prefix, 11 - Len(Value)) & Value
    6.  
    7. End Function

    _Change event code
    VB Code:
    1. Private Sub TextBox1_Change()
    2.     TextBox1.Value = Cid(TextBox1.Value)
    3. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  12. #12
    Junior Member EricDV's Avatar
    Join Date
    Dec 2005
    Location
    MN
    Posts
    16

    Re: Integers in a textbox

    VB Code:
    1. GIS.Value=Format$(GIS.Value,"R000000000")
    EricDV-Programmer

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