Home > Archive > Visual Basic > August 2005 > user input form boxes for numbers/letters
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
user input form boxes for numbers/letters
|
|
| inquirer 2005-08-25, 3:55 am |
| I am using VB6 and would like to set up a user form consisting of 10
boxes, all set to blank by default. I would then like the user to start
in box 1 and enter a number 1-26, have that number displayed in the box.
The user would then hit enter to move to box2, etc.
At the end, if an error has been made in say box 4, the user should
click on that box and input the correct number.
Then when all boxes have valid numbers, the boxes should be re-displayed
with corresponding letters of the alphabet.
Any help with getting started on this would be appreciated.
Thanks
Chris
| |
| Jan Hyde 2005-08-25, 3:55 am |
| inquirer <noreply@noreply.com>'s wild thoughts were released
on Thu, 25 Aug 2005 17:10:12 +1000 bearing the following
fruit:
>I am using VB6 and would like to set up a user form consisting of 10
>boxes, all set to blank by default. I would then like the user to start
>in box 1 and enter a number 1-26, have that number displayed in the box.
>The user would then hit enter to move to box2, etc.
>
>At the end, if an error has been made in say box 4, the user should
>click on that box and input the correct number.
>
>Then when all boxes have valid numbers, the boxes should be re-displayed
>with corresponding letters of the alphabet.
>
>Any help with getting started on this would be appreciated.
>
How far have you got?
Jan Hyde (VB MVP)
--
"You don't see the point, do you?" asked Tom, making a stab in the dark.
(Kegel Archives)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| inquirer 2005-08-25, 3:55 am |
| Jan Hyde wrote:
> inquirer <noreply@noreply.com>'s wild thoughts were released
> on Thu, 25 Aug 2005 17:10:12 +1000 bearing the following
> fruit:
>
>
>
>
> How far have you got?
>
>
>
> Jan Hyde (VB MVP)
>
Not very far - I am bogged down in just how to set up on box that does
the right thing
| |
| Jan Hyde 2005-08-25, 7:56 am |
| inquirer <noreply@noreply.com>'s wild thoughts were released
on Thu, 25 Aug 2005 17:59:57 +1000 bearing the following
fruit:
>Jan Hyde wrote:
>Not very far - I am bogged down in just how to set up on box that does
>the right thing
Rather than lay down a specification for a project and ask
how to do it (which will put off a lot of people from
helping you), ask a specifc question such as
"How do move to the next textbox when I press enter."
(I hate this, why people can't use tab - but thats another
issue)
We'll try to help you with each individual problem you come
accross. Don't be afraid to ask a lot of diffent questions.
You might want to post those pecific questions to this
thread, the information you've posted so far will help
formulate the answers you get.
Jan Hyde (VB MVP)
--
What's the difference between a tailor and a horse trainer?
One mends a tear; the other tends a mare.
(James D. Ertner)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| Rick Rothstein [MVP - Visual Basic] 2005-08-25, 6:55 pm |
| > >>>I am using VB6 and would like to set up a user form consisting of
10
start[color=darkred]
box.[color=darkred]
re-displayed[color=darkred]
does[color=darkred]
>
> Rather than lay down a specification for a project and ask
> how to do it (which will put off a lot of people from
> helping you), ask a specifc question such as
>
> "How do move to the next textbox when I press enter."
>
> (I hate this, why people can't use tab - but thats another
> issue)
>
> We'll try to help you with each individual problem you come
> accross. Don't be afraid to ask a lot of diffent questions.
>
> You might want to post those pecific questions to this
> thread, the information you've posted so far will help
> formulate the answers you get.
To add to Jan's reply, explain the format of things you need to work
with. For example, you say the user should enter a number in TextBox 1,
and then you show the number as 1-26. Unless that dash is a typo for a
decimal point, 1-26 is not considered a "number" by most people. If your
"numbers" have a specific format requirement, tells us that. Remember,
we have no idea what you are doing or why... you have to tell us
everything you know if your expect us to help you. Breaking down your
questions into smaller chunks as Jan suggested should make providing us
with this "special" information easier to do.
Rick
| |
| RonW@no_domain.invalid 2005-08-25, 6:55 pm |
| On Thu, 25 Aug 2005 12:50:58 -0400, "Rick Rothstein [MVP - Visual Basic]"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote:
>To add to Jan's reply, explain the format of things you need to work
>with. For example, you say the user should enter a number in TextBox 1,
>and then you show the number as 1-26. Unless that dash is a typo for a
>decimal point, 1-26 is not considered a "number" by most people. If your
>"numbers" have a specific format requirement, tells us that. Remember,
>we have no idea what you are doing or why... you have to tell us
>everything you know if your expect us to help you. Breaking down your
>questions into smaller chunks as Jan suggested should make providing us
>with this "special" information easier to do.
>
>Rick
>
Hey Rick,
Sounds to me like the OP wants 10 textboxes that users type a number into, the
number constrained to the _range_ 1 to 26 (1-26). After all is accepted by the
program change the text in the textboxes from numbers to corresponding letters
of the alphabet (1=A, 2=B,,,,26=Z).
That's my take on things, anyway.
Nonetheless, agreed, the OP needs to be more specific in the help they are
s ing.
RonW
| |
| inquirer 2005-08-25, 9:55 pm |
| Jan Hyde wrote:
> inquirer <noreply@noreply.com>'s wild thoughts were released
> on Thu, 25 Aug 2005 17:59:57 +1000 bearing the following
> fruit:
>
>
>
>
> Rather than lay down a specification for a project and ask
> how to do it (which will put off a lot of people from
> helping you), ask a specifc question such as
>
> "How do move to the next textbox when I press enter."
>
> (I hate this, why people can't use tab - but thats another
> issue)
>
> We'll try to help you with each individual problem you come
> accross. Don't be afraid to ask a lot of diffent questions.
>
> You might want to post those pecific questions to this
> thread, the information you've posted so far will help
> formulate the answers you get.
>
>
>
> Jan Hyde (VB MVP)
>
Points all taken - I should have been a lot more specific. I originally
started to do this in VBA in excel but wanted not to have excel involved
so I started coding in VB6 but had trouble with the different syntax.
Then I imported the module and form from excel into vb and at least got
started.
The problem I have is that when I run the code it vb, how to I get the
from to come to the front so I can see it. When I run it now I have to
minimise all open windows to see the form so I can input data.
The code I have below is very very basic (pardon the pun) but it gives
me an idea of how to proceed - I have to put in error checking etc. The
form has 3 boxes and a command button on it.
I plan to do the error checking in sub main and keep showing the form
after amendments have been made to it. Is the way I have indicated the
best or are there other methods to do this?
Thanks Chris
Sub main()
Load UserForm1
UserForm1.Show
a = UserForm1.TextBox1.Value
b = UserForm1.TextBox2.Value
c = UserForm1.TextBox3.Value
If a = 1 Then UserForm1.TextBox1.Value = "A"
If b = 2 Then UserForm1.TextBox2.Value = "B"
If c = 3 Then UserForm1.TextBox3.Value = "C"
UserForm1.Show
Unload UserForm1
End Sub
Private Sub UserForm_Initialize()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
End Sub
Private Sub CommandButton1_Click()
Me.Hide
End Sub
| |
| inquirer 2005-08-26, 3:55 am |
| inquirer wrote:
> Jan Hyde wrote:
>
> Points all taken - I should have been a lot more specific. I originally
> started to do this in VBA in excel but wanted not to have excel involved
> so I started coding in VB6 but had trouble with the different syntax.
> Then I imported the module and form from excel into vb and at least got
> started.
> The problem I have is that when I run the code it vb, how to I get the
> from to come to the front so I can see it. When I run it now I have to
> minimise all open windows to see the form so I can input data.
>
> The code I have below is very very basic (pardon the pun) but it gives
> me an idea of how to proceed - I have to put in error checking etc. The
> form has 3 boxes and a command button on it.
>
> I plan to do the error checking in sub main and keep showing the form
> after amendments have been made to it. Is the way I have indicated the
> best or are there other methods to do this?
>
> Thanks Chris
>
> Sub main()
>
> Load UserForm1
> UserForm1.Show
> a = UserForm1.TextBox1.Value
> b = UserForm1.TextBox2.Value
> c = UserForm1.TextBox3.Value
> If a = 1 Then UserForm1.TextBox1.Value = "A"
> If b = 2 Then UserForm1.TextBox2.Value = "B"
> If c = 3 Then UserForm1.TextBox3.Value = "C"
> UserForm1.Show
> Unload UserForm1
> End Sub
>
> Private Sub UserForm_Initialize()
> TextBox1.Value = ""
> TextBox2.Value = ""
> TextBox3.Value = ""
> End Sub
>
> Private Sub CommandButton1_Click()
> Me.Hide
> End Sub
>
>
>
Here is a specific question...
I have n textboxes on a form and each text box contains a number in the
range 1 to 26.
I have array(26) where array(1)=A array(2)=B etc
I want to do something like this but don't know how to refer to the textbox
for i=1 to n
textboxi.value=array(textboxi.value)
next i
ie for the ith textbox, make its value equal to the alphabetic
equivalent of the number that was in the textbox.
Thanks
Chris
| |
| Jan Hyde 2005-08-26, 3:55 am |
| inquirer <noreply@noreply.com>'s wild thoughts were released
on Fri, 26 Aug 2005 15:54:52 +1000 bearing the following
fruit:
>Here is a specific question...
>I have n textboxes on a form and each text box contains a number in the
>range 1 to 26.
>I have array(26) where array(1)=A array(2)=B etc
>
>I want to do something like this but don't know how to refer to the textbox
>
>for i=1 to n
> textboxi.value=array(textboxi.value)
>next i
Use control arrays
>ie for the ith textbox, make its value equal to the alphabetic
>equivalent of the number that was in the textbox.
If use use control arrays you can do somthing like this
For i = Text1.LBound to Text1.Ubound
TextBox1(i).Text = Array(val(textbox1(i).text))
Next
[Of course, there would have be an equal number of array
element to the number of textboxes]
I've added a Val statement to stop any errors when the
textbox is blank (Val will force it to 0) Hoever this is
something you should cater for.
Jan Hyde (VB MVP)
--
Zebra: A large undergarment that's an utter farce (Stan Kegel)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| inquirer 2005-08-26, 3:55 am |
| Jan Hyde wrote:
> inquirer <noreply@noreply.com>'s wild thoughts were released
> on Fri, 26 Aug 2005 15:54:52 +1000 bearing the following
> fruit:
>
>
>
>
> Use control arrays
>
>
>
>
> If use use control arrays you can do somthing like this
>
> For i = Text1.LBound to Text1.Ubound
> TextBox1(i).Text = Array(val(textbox1(i).text))
> Next
>
> [Of course, there would have be an equal number of array
> element to the number of textboxes]
>
> I've added a Val statement to stop any errors when the
> textbox is blank (Val will force it to 0) Hoever this is
> something you should cater for.
>
>
>
> Jan Hyde (VB MVP)
>
Thanks Jan, I will give that a try
Chris
| |
|
|
> [Of course, there would have be an equal number of array
> element to the number of textboxes]
Why? the array is just A-Z, he could have less than 26 text boxes.
Also the array seems a waste of time as long as the boxes definately have a
value between 1 and 26
TextBox(i).text = chr$(val(TextBox(i).text) + 64)
Regards
Dave.
| |
| Jan Hyde 2005-08-26, 7:55 am |
| "Dave" <Nobody@Nowhere.Com>'s wild thoughts were released on
Fri, 26 Aug 2005 10:21:42 +0100 bearing the following fruit:
>
>
>Why? the array is just A-Z, he could have less than 26 text boxes.
Hmm, I though I'd included an 'at least'
>Also the array seems a waste of time as long as the boxes definately have a
>value between 1 and 26
>
>TextBox(i).text = chr$(val(TextBox(i).text) + 64)
I thought that too, but with an array you could change the
mapping of number to letters by switching the contents of
the array elements.
Although you could just a well have asked, why not type the
letter in itself, a whole lot easier ;-)
Jan Hyde (VB MVP)
--
Zebra: A large undergarment that's an utter farce (Stan Kegel)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
| |
| inquirer 2005-08-29, 3:55 am |
| inquirer wrote:[color=darkred]
> Jan Hyde wrote:
>
I must be missing something as when I try to run
For i = UserForm1.TextBox1.LBound To UserForm1.TextBox1.Ubound
UserForm1.TextBox1(i).Text = darray(Val(UserForm1.TextBox1(i).Text))
Next
I get a compile error
Method or datamember not found. and LBound is highlighted.
If I use
For i = 1 To 26
UserForm1.TextBox(i).Text = Chr$(Val(UserForm1.TextBox(i).Text) + 64)
Next i
I get the same error with TextBox in Val(UserForm1.TextBox(i).Text
Chris
| |
| Jan Hyde 2005-08-30, 3:55 am |
| inquirer <noreply@noreply.com>'s wild thoughts were released
on Mon, 29 Aug 2005 13:07:50 +1000 bearing the following
fruit:
>inquirer wrote:
>
>I must be missing something as when I try to run
>
>For i = UserForm1.TextBox1.LBound To UserForm1.TextBox1.Ubound
> UserForm1.TextBox1(i).Text = darray(Val(UserForm1.TextBox1(i).Text))
>Next
>
>I get a compile error
>Method or datamember not found. and LBound is highlighted.
>
>If I use
>For i = 1 To 26
> UserForm1.TextBox(i).Text = Chr$(Val(UserForm1.TextBox(i).Text) + 64)
>Next i
>
>I get the same error with TextBox in Val(UserForm1.TextBox(i).Text
>
Then you do not have a control array.
Jan Hyde (VB MVP)
--
"Clones are only imaginary!" Tom said, beside himself. (Stan Kegel)
[Abolish the TV Licence - http://www.tvlicensing.biz/]
|
|
|
|
|