|
-
Jan 24th, 2006, 01:46 PM
#1
Thread Starter
Fanatic Member
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:
Private Sub Form_Load()
On Error GoTo move_first
Do
If GIS.Value = "xxxx" Then
GIS.Value = "R00000" & GIS.Value
ElseIf GIS.Value = "xxxxx" Then
GIS.Value = "R0000" & GIS.Value
Me.Recordset.MoveNext
End If
Loop
Exit Sub
move_first:
Me.Recordset.MoveFirst
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
-
Jan 24th, 2006, 01:51 PM
#2
Fanatic Member
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
-
Jan 24th, 2006, 01:52 PM
#3
Re: Integers in a textbox
What kind of control is GIS?
-
Jan 24th, 2006, 02:35 PM
#4
Thread Starter
Fanatic Member
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"
-
Jan 24th, 2006, 02:38 PM
#5
Re: Integers in a textbox
 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.
-
Jan 24th, 2006, 02:38 PM
#6
Thread Starter
Fanatic Member
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.
-
Jan 24th, 2006, 02:41 PM
#7
Re: Integers in a textbox
 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.
-
Jan 24th, 2006, 02:43 PM
#8
Thread Starter
Fanatic Member
Re: Integers in a textbox
ok, thanks... any other information on my problem would be helpful.
Thanks guys.
-
Jan 24th, 2006, 02:45 PM
#9
Re: Integers in a textbox
Try a formula like this:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim a As String, s As String
a = "124"
s = "R" & String$(10 - Len(a), "0") & a
MsgBox s & " " & Len(s)
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.
-
Jan 24th, 2006, 02:47 PM
#10
Thread Starter
Fanatic Member
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.
-
Jan 24th, 2006, 03:00 PM
#11
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:
Function Cid(Value As String) As String
Const Prefix As String = "R0000000000"
Cid = Left(Prefix, 11 - Len(Value)) & Value
End Function
_Change event code
VB Code:
Private Sub TextBox1_Change()
TextBox1.Value = Cid(TextBox1.Value)
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jan 24th, 2006, 03:04 PM
#12
Junior Member
Re: Integers in a textbox
VB Code:
GIS.Value=Format$(GIS.Value,"R000000000")
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|