msvisual.com Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

seach for character

 
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax
Author Message
jensingretro184



Joined: 15 Nov 2007
Posts: 1

PostPosted: Thu Nov 15, 2007 5:49 am    Post subject: seach for character Reply with quote

Hello I am Jay I have a problem with my vb6 project. This is my assignment
all I have to do is to type in a string of characters in one textbox. That
string of characters should appear backwards, and in numbers text form.
Eaxmple if I type in "abc" it should appear "cba" and with numbers"123" it
should appear text one, two, three. The program works, but when I type in my
string of characters instead of my program accessing one character like "a"
in reads the whole string"abc". All I need to do is read one character, not
the entire string, do anyone have an idea or suggestion I would gladly like
to here your suggestion.
Here is my code:

Private Sub textname11_Change()

textname12.Text = textname11.Text

Dim base As String, position As Integer
'to count the letter
'Dim strname1 As String
'strname1 is the variable for the number
Dim strname2 As String
'strname2 is the variable fot the letter

'strname1 = textname12.Text

' base = textname12.Text

'textname12.Text = ""
' For position = Len(base) To 1 Step -1
' textname12.Text = textname12.Text & _
' Mid$(base, position, 1)
' Next

intnum1 = textname12.Text
Select Case textname12.Text
Case "0"
textname12.Text = "zero "
Case "1"
textname12.Text = "one "
Case "2"
textname12.Text = "two "
Case "3"
textname12.Text = "three "
Case "4"
textname12.Text = "four "
Case "5"
textname12.Text = "five "
Case "6"
textname12.Text = "six "
Case "7"
textname12.Text = "seven "
Case "8"
textname12.Text = "eight "
Case "9"
textname12.Text = "nine "
Case Else
textname12.Text = strname1

End Select

strname2 = strname1
End Sub
Jay

Archived from group: microsoft>public>vb>syntax
Back to top
View user's profile Send private message
"Jan Hyde



Joined: 04 Oct 2007
Posts: 466

PostPosted: Thu Nov 15, 2007 2:12 pm    Post subject: Re: seach for character Reply with quote

"jensingretro184" 's wild thoughts were released
on Thu, 15 Nov 2007 00:49:48 GMT bearing the following
fruit:

>Hello I am Jay I have a problem with my vb6 project. This is my assignment
>all I have to do is to type in a string of characters in one textbox. That
>string of characters should appear backwards, and in numbers text form.
>Eaxmple if I type in "abc" it should appear "cba" and with numbers"123" it
>should appear text one, two, three. The program works, but when I type in my
>string of characters instead of my program accessing one character like "a"
>in reads the whole string"abc". All I need to do is read one character, not
>the entire string, do anyone have an idea or suggestion I would gladly like
>to here your suggestion.
>Here is my code:

keypress, keydown etc - these events report which key was
pressed.

--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Back to top
View user's profile Send private message
jensingretro184 via VBMon



Joined: 16 Nov 2007
Posts: 1

PostPosted: Fri Nov 16, 2007 4:34 am    Post subject: Re: seach for character Reply with quote

Hello I am Jay I have a problem with my vb6 project. This is my assignment
all I have to do is to type in a string of characters in one text box. That
string of characters should appear backwards, and in numbers text form in the
second text box.
Example if I type in "abc" it should appear "cba" and with numbers"123" it
should appear text one, two, three. The program works, but when I type in my
string of characters instead of my program accessing one character like "a"
in reads the whole string"abc". All I need to do is read one character, not
the entire string, do anyone have an idea or suggestion I would gladly like
to here your suggestion.
Here is my code

Private Sub textname11_Change()

textname12.Text = textname11.Text

Dim base As String, position As Integer
to count the letter
Dim strname1 As String
strname1 is the variable for the number
Dim strname2 As String
strname2 is the variable fot the letter

strname1 = textname12.Text

base = textname12.Text

textname12.Text = ""
For position = Len(base) To 1 Step -1
textname12.Text = textname12.Text & _
Mid$(base, position, 1)
Next

intnum1 = textname12.Text
Select Case textname12.Text
Case "0"
textname12.Text = "zero "
Case "1"
textname12.Text = "one "
Case "2"
textname12.Text = "two "
Case "3"
textname12.Text = "three "
Case "4"
textname12.Text = "four "
Case "5"
textname12.Text = "five "
Case "6"
textname12.Text = "six "
Case "7"
textname12.Text = "seven "
Case "8"
textname12.Text = "eight "
Case "9"
textname12.Text = "nine "
Case Else
textname12.Text = strname1

End Select

strname2 = strname1
End Sub
Jay

--
Message posted via VBMonster.com
http://www.vbmonster.com/Uwe/Forums.aspx/vb-syntax/200711/1
Back to top
View user's profile Send private message
"Jan Hyde



Joined: 04 Oct 2007
Posts: 466

PostPosted: Fri Nov 16, 2007 2:06 pm    Post subject: Re: seach for character Reply with quote

"jensingretro184 via VBMonster.com" 's wild
thoughts were released on Thu, 15 Nov 2007 23:34:38 GMT
bearing the following fruit:

>Hello I am Jay I have a problem with my vb6 project. This is my assignment
>all I have to do is to type in a string of characters in one text box. That
>string of characters should appear backwards, and in numbers text form in the
>second text box.
>Example if I type in "abc" it should appear "cba" and with numbers"123" it
>should appear text one, two, three. The program works, but when I type in my
>string of characters instead of my program accessing one character like "a"
>in reads the whole string"abc". All I need to do is read one character, not
>the entire string, do anyone have an idea or suggestion I would gladly like
>to here your suggestion.
>Here is my code

reposting the original question isn't going to help
us move along. did you read my answer? did you try anything?
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Back to top
View user's profile Send private message
Randy Birch



Joined: 04 Oct 2007
Posts: 1768

PostPosted: Fri Nov 16, 2007 3:04 pm    Post subject: Re: seach for character Reply with quote

Sounds like you have a few things to consider. Since this group
traditionally doesn't provide code for assignments but rather pointers (so
you learn), here's my suggestions.

- you have to use code in a key event to determine what was pressed. Waiting
until the text box is populated is a newbie step, and is too late.

- in the key event - most likely keyup unless you want to allow repeated
characters in which case you'd use keydown - you need a number of select
case statements

- the values of the keys being pressed are returned to the key events as
ANSI code values, not characters, meaning your select case statements would
test for those values, rather than the string "a" or number "3" itself. See
the VB help for translating ANSI (aka ASCII) codes to strings and vice
versa.

- the main (outside) select statement would deal with whether the key
pressed was in the numeric ANSI range, or the character ANSI range. This is
straightforward enough. (Hint: you can use "To" to specifiy a range, e.g.
Case 49 to 55.)

- once you know if a keypress represents a char or number, your code inside
that case statement would process the keystroke to display the appropriate
text. For a character key you would move the cursor to the front of the
textbox using the SelStart property, and add the Chr$(xxx) value to the
textbox using SelText. For numeric keys, you'd use SelStart to move to the
end of the text box, add a space, and use code similar to as you already
have to change the number into text.

There are other intracies to consider, such as how to handle spaces between
numbers - do you add them when each key is pressed and the text translated,
or when each number-to-text string is added to the text box? Each has
benefits that could impact upon the mark - for example, adding them when the
text for each key is added (e.g. "one ", "two " etc) means there will always
be a trailing space after the last key is entered. Changing this around to
" one", " two" etc now means a leading space will be added before the first
item added. So a good program would determine whether the string already
contains data, and if no (aka this is the first item being added), not add
the space; if data already exists, add the space. Another condsideration is
how to handle backspace, and possibly even how to handle situations were a
user pastes data into the text box rather than type (in which case the key
events won't fire but the Change event will). And what about multiple case
situations - e.g. the user types ab123c? Is the resulting text supposed to
look like "cba one two three", or "c one two three ba" ?

--

Randy
http://vbnet.mvps.org/


"jensingretro184 via VBMonster.com" wrote in message @uwe...
> Hello I am Jay I have a problem with my vb6 project. This is my assignment
> all I have to do is to type in a string of characters in one text box.
> That
> string of characters should appear backwards, and in numbers text form in
> the
> second text box.
> Example if I type in "abc" it should appear "cba" and with numbers"123" it
> should appear text one, two, three. The program works, but when I type in
> my
> string of characters instead of my program accessing one character like
> "a"
> in reads the whole string"abc". All I need to do is read one character,
> not
> the entire string, do anyone have an idea or suggestion I would gladly
> like
> to here your suggestion.
> Here is my code
>
> Private Sub textname11_Change()
>
> textname12.Text = textname11.Text
>
> Dim base As String, position As Integer
> to count the letter
> Dim strname1 As String
> strname1 is the variable for the number
> Dim strname2 As String
> strname2 is the variable fot the letter
>
> strname1 = textname12.Text
>
> base = textname12.Text
>
> textname12.Text = ""
> For position = Len(base) To 1 Step -1
> textname12.Text = textname12.Text & _
> Mid$(base, position, 1)
> Next
>
> intnum1 = textname12.Text
> Select Case textname12.Text
> Case "0"
> textname12.Text = "zero "
> Case "1"
> textname12.Text = "one "
> Case "2"
> textname12.Text = "two "
> Case "3"
> textname12.Text = "three "
> Case "4"
> textname12.Text = "four "
> Case "5"
> textname12.Text = "five "
> Case "6"
> textname12.Text = "six "
> Case "7"
> textname12.Text = "seven "
> Case "8"
> textname12.Text = "eight "
> Case "9"
> textname12.Text = "nine "
> Case Else
> textname12.Text = strname1
>
> End Select
>
> strname2 = strname1
> End Sub
> Jay
>
> --
> Message posted via VBMonster.com
> http://www.vbmonster.com/Uwe/Forums.aspx/vb-syntax/200711/1
>

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    msvisual.com Forum Index -> VB Syntax All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group