473,609 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox input

As a pre-newbie to visual basic, I haven't programmed for years and I
am having the greatest of difficulties coping with it. If any kind
soul can help me out with advice then I'd be most grateful.

I am at the stage where I can design a form where I can insert text
boxes. You type in a word in textbox1, press OK and it appears in
textbox2. Not rocket science I know. But I trust this gives you a
feel for my level.

What I want to do is this:

As you type a character into textbox1 then this character is instantly
displayed in textbox2 and, this for me is the tricky bit, YOU DON'T
NEED TO PRESS RETURN or OK or any button at all. Please excuse the
shouting.

(What I will be designing eventually will be a translation program
which converts Roman numerals into Arabic numerals. Each letter as
entered in textbox1 will be translated into Arabic numerals, after
validation, and displayed in textbox2. I've written the validation
algorithm, have desk-checked it and it works.)

Before anyone feels tempted to flame or to scorn, I have RTFM, in fact
various FM's and nothing seems to help here. InputBoxes won't do, of
course.

In ye old BASIC it might go something like this

INPUT "Type in a letter"; letter$
GOSUB loads of validation and processing
PRINT letter$

This probably looks like Elvish to anyone born after 1980.

Thanks if you can help.

Bob
Jul 17 '05 #1
12 13250
> As a pre-newbie to visual basic, I haven't programmed for years and I
am having the greatest of difficulties coping with it. If any kind
soul can help me out with advice then I'd be most grateful.

I am at the stage where I can design a form where I can insert text
boxes. You type in a word in textbox1, press OK and it appears in
textbox2. Not rocket science I know. But I trust this gives you a
feel for my level.

What I want to do is this:

As you type a character into textbox1 then this character is instantly
displayed in textbox2 and, this for me is the tricky bit, YOU DON'T
NEED TO PRESS RETURN or OK or any button at all. Please excuse the
shouting.

(What I will be designing eventually will be a translation program
which converts Roman numerals into Arabic numerals. Each letter as
entered in textbox1 will be translated into Arabic numerals, after
validation, and displayed in textbox2. I've written the validation
algorithm, have desk-checked it and it works.)

Before anyone feels tempted to flame or to scorn, I have RTFM, in fact
various FM's and nothing seems to help here. InputBoxes won't do, of
course.

In ye old BASIC it might go something like this

INPUT "Type in a letter"; letter$
GOSUB loads of validation and processing
PRINT letter$

This probably looks like Elvish to anyone born after 1980.


Forget the "old" BASIC... it will only hold back your thinking. For a
TextBox, the Change event is fired each time text in the TextBox changes. To
answer your stated question,

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

will update the text in Text2 whenever something is type (or deleted) in
Text1. To do the conversions you indicated you wanted to do, you would put
that conversion code in the Change event of Text1.

Rick - MVP
Jul 17 '05 #2
In addition to what Rick said, this will help with the roman-to-Arabic
number conversion ..
http://www.mvps.org/vbnet/code/helpe...bertoroman.htm

--

Randy Birch
MVP Visual Basic
http://www.mvps.org/vbnet/
Please respond only to the newsgroups so all can benefit.
"Robert" <sh************ ***@yahoo.co.uk > wrote in message
news:95******** *************** ***@posting.goo gle.com...
: As a pre-newbie to visual basic, I haven't programmed for years and I
: am having the greatest of difficulties coping with it. If any kind
: soul can help me out with advice then I'd be most grateful.
:
: I am at the stage where I can design a form where I can insert text
: boxes. You type in a word in textbox1, press OK and it appears in
: textbox2. Not rocket science I know. But I trust this gives you a
: feel for my level.
:
: What I want to do is this:
:
: As you type a character into textbox1 then this character is instantly
: displayed in textbox2 and, this for me is the tricky bit, YOU DON'T
: NEED TO PRESS RETURN or OK or any button at all. Please excuse the
: shouting.
:
: (What I will be designing eventually will be a translation program
: which converts Roman numerals into Arabic numerals. Each letter as
: entered in textbox1 will be translated into Arabic numerals, after
: validation, and displayed in textbox2. I've written the validation
: algorithm, have desk-checked it and it works.)
:
: Before anyone feels tempted to flame or to scorn, I have RTFM, in fact
: various FM's and nothing seems to help here. InputBoxes won't do, of
: course.
:
: In ye old BASIC it might go something like this
:
: INPUT "Type in a letter"; letter$
: GOSUB loads of validation and processing
: PRINT letter$
:
: This probably looks like Elvish to anyone born after 1980.
:
: Thanks if you can help.
:
: Bob
Jul 17 '05 #3
Thanks to you both for taking the time and trouble to write. That
seemed to do the trick.

Bob
Jul 17 '05 #4
Thanks to you both for taking the time and trouble to write. That
seemed to do the trick.
Bob
Jul 17 '05 #5
The coding

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

worked a treat. Thanks again.

Sorry to be so thick but when you say "To do the conversions you
indicated you wanted to do, you would put that conversion code in the
Change event of Text1." does that mean like this?

Private Sub Text1_Change(co nversion/validation code here?)
Text2.Text = Text1.Text
End Sub

I've done quite a bit of experimenting and can't seem to get that to
work. I suspect I'm doing something fundamentally wrong which won't be
for the first time. As I have things at the moment an M produces 1000
in textbox1 AND textbox2 (good), a repeated M produces 2000 (good)
but any other letter does too, even a backspace, despite all my case
statements.

Thanks for any helpful indications.

Bob

"Rick Rothstein" <ri************ @NOSPAMcomcast. net> wrote in message news:<P5******* *************@c omcast.com>...
As a pre-newbie to visual basic, I haven't programmed for years and I
am having the greatest of difficulties coping with it. If any kind
soul can help me out with advice then I'd be most grateful.

I am at the stage where I can design a form where I can insert text
boxes. You type in a word in textbox1, press OK and it appears in
textbox2. Not rocket science I know. But I trust this gives you a
feel for my level.

What I want to do is this:

As you type a character into textbox1 then this character is instantly
displayed in textbox2 and, this for me is the tricky bit, YOU DON'T
NEED TO PRESS RETURN or OK or any button at all. Please excuse the
shouting.

(What I will be designing eventually will be a translation program
which converts Roman numerals into Arabic numerals. Each letter as
entered in textbox1 will be translated into Arabic numerals, after
validation, and displayed in textbox2. I've written the validation
algorithm, have desk-checked it and it works.)

Before anyone feels tempted to flame or to scorn, I have RTFM, in fact
various FM's and nothing seems to help here. InputBoxes won't do, of
course.

In ye old BASIC it might go something like this

INPUT "Type in a letter"; letter$
GOSUB loads of validation and processing
PRINT letter$

This probably looks like Elvish to anyone born after 1980.


Forget the "old" BASIC... it will only hold back your thinking. For a
TextBox, the Change event is fired each time text in the TextBox changes. To
answer your stated question,

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

will update the text in Text2 whenever something is type (or deleted) in
Text1. To do the conversions you indicated you wanted to do, you would put
that conversion code in the Change event of Text1.

Rick - MVP

Jul 17 '05 #6
> The coding

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

worked a treat. Thanks again.

Sorry to be so thick but when you say "To do the conversions you
indicated you wanted to do, you would put that conversion code in the
Change event of Text1." does that mean like this?

Private Sub Text1_Change(co nversion/validation code here?)
Text2.Text = Text1.Text
End Sub


No, like this...

Private Sub Text1_Change()
' Do something with Text1.Text
' Assign it to Text2.Text
End Sub

For example, let's say you wanted to make anything typed in Text1 be
repeated in Text2, but in all caps. You could use the built-in UCase$
function like this

Private Sub Text1_Change()
Text2.Text = UCase$(Text1.Te xt)
End Sub

Use what ever conversion code you have (it could be a function like above,
or it could take place in-line over several lines) in place of the function
above.

Rick - MVP
Jul 17 '05 #7
A simple Roman numeral calculator.

More help appreciated if anyone has a few moments. Thanks.

Below is the code for textbox1 (without all the processing in each
case statement, of course, to make things clearer and omitting all the
declarations to keep it shorter).

At the moment ‘m' or another Roman letter typed in textbox1 produces
1000 in textbox2 or the corresponding value of that Roman letter.

‘mm' typed in textbox1 produces 0 in textbox2 but with a ‘backspace'
to ‘m' you get 2000 in textbox2. The logic of this is clear,
naturally.

However I would like ‘mm' in textbox1 to produce 2000, ‘mmc' to
produce 2100.

I thought the answer might lie in something like textbox1_keypre ss
with which I have been experimenting but cannot get this to work at
all.

Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles TextBox1.TextCh anged

ROMAN = TextBox1.Text
ROMAN = UCase(ROMAN)

Select Case ROMAN

Case Is = "M"
NEWNUMBER = 1000

Case Is = "D"
NEWNUMBER = 500

Case Is = "C"
NEWNUMBER = 100

Case Is = "L"
NEWNUMBER = 50

Case Is = "X"
NEWNUMBER = 10

Case Is = "V"
NEWNUMBER = 5

Case Is = "I"
NEWNUMBER = 1

Case Else
NEWNUMBER = 0

End Select

SUM = SUM + NEWNUMBER
TextBox2.Text = SUM
End Sub

Thanks for any help or indications.

Bob
"Rick Rothstein" <ri************ @NOSPAMcomcast. net> wrote in message news:<Bv******* *************@c omcast.com>...
The coding

Private Sub Text1_Change()
Text2.Text = Text1.Text
End Sub

worked a treat. Thanks again.

Sorry to be so thick but when you say "To do the conversions you
indicated you wanted to do, you would put that conversion code in the
Change event of Text1." does that mean like this?

Private Sub Text1_Change(co nversion/validation code here?)
Text2.Text = Text1.Text
End Sub


No, like this...

Private Sub Text1_Change()
' Do something with Text1.Text
' Assign it to Text2.Text
End Sub

For example, let's say you wanted to make anything typed in Text1 be
repeated in Text2, but in all caps. You could use the built-in UCase$
function like this

Private Sub Text1_Change()
Text2.Text = UCase$(Text1.Te xt)
End Sub

Use what ever conversion code you have (it could be a function like above,
or it could take place in-line over several lines) in place of the function
above.

Rick - MVP

Jul 17 '05 #8
> Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles TextBox1.TextCh anged


OH!!!! You are using VB.NET. Almost any advice you get here will be the
incorrect way for you to proceed. Here is my standard reply to people who
indicate they are using VB.NET

Almost everybody in this newsgroup is using VB6 or lower. While you may get
a stray answer to VB.NET questions here, you should ask them in newsgroups
devoted exclusively to .NET programming. Look for newsgroups with either the
word "dotnet" or "vsnet" in their name.

For the microsoft news server, try these newsgroups...

microsoft.publi c.dotnet.genera l
microsoft.publi c.dotnet.langua ges.vb
microsoft.publi c.vsnet.general

For the news.devx.com news server, try these

vb.dotnet.discu ssion
vb.dotnet.techn ical

There are some others, but these should get you started.

Rick - MVP
Jul 17 '05 #9
On 2 Nov 2003 03:05:58 -0800, sh************* **@yahoo.co.uk (Robert)
wrote:
A simple Roman numeral calculator.

More help appreciated if anyone has a few moments. Thanks.

Below is the code for textbox1 (without all the processing in each
case statement, of course, to make things clearer and omitting all the
declarations to keep it shorter).

At the moment ‘m' or another Roman letter typed in textbox1 produces
1000 in textbox2 or the corresponding value of that Roman letter.

‘mm' typed in textbox1 produces 0 in textbox2 but with a ‘backspace'
to ‘m' you get 2000 in textbox2. The logic of this is clear,
naturally.

However I would like ‘mm' in textbox1 to produce 2000, ‘mmc' to
produce 2100.

I thought the answer might lie in something like textbox1_keypre ss
with which I have been experimenting but cannot get this to work at
all.

Private Sub TextBox1_TextCh anged(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles TextBox1.TextCh anged

ROMAN = TextBox1.Text
ROMAN = UCase(ROMAN)

Select Case ROMAN

Case Is = "M"
NEWNUMBER = 1000

Case Is = "D"
NEWNUMBER = 500

Case Is = "C"
NEWNUMBER = 100

Case Is = "L"
NEWNUMBER = 50

Case Is = "X"
NEWNUMBER = 10

Case Is = "V"
NEWNUMBER = 5

Case Is = "I"
NEWNUMBER = 1

Case Else
NEWNUMBER = 0

End Select

SUM = SUM + NEWNUMBER
TextBox2.Text = SUM
End Sub

Thanks for any help or indications.


Your algorithm needs some work. You're assuming textbox1.text is one
character in length. You need to loop through textbox1.text one
character at a time. Have a look at VB string functions.

Also there are positional rules in roman numerals where, for example:

VI = 5 + 1 = 6
IV = 5 - 1 = 4

Your algorithm needs to keep track of the preceding character and
determine if it is less than, greater than or equal to the current
character.

There are also some other rules to consider. I seem to recall that you
should never have a string of four identical characters (eg. IIII for
4 instead of IV). Although, I do recall that IIII is acceptable on
clocks, sundials or perhaps it's garden sundials - some timekeeping
application anyway.
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
13694
by: anonieko | last post by:
This applies to javascript dynamic textbox onkey > > > Newsgroups: comp.lang.javascript From: Lasse Reichstein Nielsen <l...@hotpop.com> - Find messages by this author Date: Fri, 15 Jul 2005 18:39:24 +0200 Local: Fri,Jul 15 2005 12:39 pm Subject: Re: Summer 2005 browsers' test set ?
9
10093
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control, possibly a custom validator with a function written in javascript. Has anyone done this? Does someone have an example? Regards
7
2109
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the following: (TextBox)UserPrefix=(TextBox)e.Item.Cells.Controls; string strUserPrefix=UserPrefix.Text; I keep getting the following error and I don't know why because I have declared the UserPrefix as a textbox using "protected...
3
3982
by: Justin Morris via DotNetMonster.com | last post by:
<asp:TextBox ID="TextBox1" runat="server" value='<%=Server.HtmlEncode (Request.Cookies("Username")("Username"))%>'/> <input name="Password" type="text" id="Password" value='<% =Server.HtmlEncode(Request.Cookies("Username")("Username"))%>'> i have created a cookie and want to use it with my login page. I currently have asp:TextBox with form validation control. I can get the cookie value to appear but not in the asp:TextBox. I can use a...
1
9350
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i need to open the new page in the main page window with passing the two textbox parameters into the new page. Program opens the new page but dont know how to pass the two textboxes values into the new page name deceasedToday.asp Needs help in...
5
15136
by: Kulgan | last post by:
Hi all, Is it possible in javascript to add a textbox when the last of three radiobuttons is clicked ? thanks !
3
10790
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one months date in another textbox. and while pressing the second button (submit) i need to display the date displayed in the textbox as itself and the records between thoses two dates. if that date is still there in the textbox only i can sort the...
1
5061
by: sparksol | last post by:
I have a form with a drop down box. If you select an option in the drop down box (depending which option is selected) one or two textbox(es) and a submit button display. I would like to keep the textbox(es) and the submit button showing until another option is selected. Also the data that's submitted is showing on the form page. Here's an example - I need the code below to do this: 1. I go to the page - I see a drop down box. 2. I...
1
2449
by: rakeshnair | last post by:
i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other... eg...when i enter product id in the first cell, the product name and its rate should come in the next two cells...it should take from the data base... it's my code........ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <%@ page import="java.sql.*"...
0
8136
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8086
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8574
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8551
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5521
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1679
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.