Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 1st, 2005, 8:00 PM   #1
AngelX
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 AngelX is on a distinguished road
Help with a counting problem.

I'm very new to programming and this one has stumped me. Im trying to make a counter that will go up by one everytime, but will be put on the end of a value typed into a text box and everytime the program loops it'll go up by one so like this

1st:User
2nd:User1
etc.

Any help?
AngelX is offline   Reply With Quote
Old Apr 1st, 2005, 10:16 PM   #2
Cipher
Hobbyist Programmer
 
Cipher's Avatar
 
Join Date: Feb 2005
Location: /home/cipher
Posts: 123
Rep Power: 4 Cipher is on a distinguished road
Send a message via AIM to Cipher Send a message via MSN to Cipher
Glad you made it AngelX, Oobs will help you, won't you oobs

I'm not quite sure yet how to do it. Sorry.
__________________
And there was much rejoicing... Yay....
Cipher is offline   Reply With Quote
Old Apr 2nd, 2005, 2:38 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
Well, to append a string to another, use the & operator:
string1 = "Hello "
string2 = "World."
string3 = string1 & string2
' string3 = "Hello World."

And to increment a counter, declare it as global or static, and increase it on the button click:
Private Sub Button1_Click
	Static count As Integer
	
	count = count + 1
End Sub
You can figure out the rest.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 2nd, 2005, 2:55 PM   #4
AngelX
Newbie
 
Join Date: Apr 2005
Posts: 2
Rep Power: 0 AngelX is on a distinguished road
Ok now it's doing User, User1, User12 o.o

count = count + 1
txtuser.Text = txtuser.Text & count
lbluser.Caption = txtuser.Text
AngelX is offline   Reply With Quote
Old Apr 2nd, 2005, 6:04 PM   #5
chepfaust
Programmer
 
chepfaust's Avatar
 
Join Date: Feb 2005
Posts: 62
Rep Power: 4 chepfaust is on a distinguished road
Quote:
Originally Posted by AngelX
Ok now it's doing User, User1, User12 o.o

count = count + 1
txtuser.Text = txtuser.Text & count
lbluser.Caption = txtuser.Text
that's because what your code is doing is adding the current number onto the previous result.

when you run through the program the first time, you're adding "1" to "user" to produce "user1."
when you run through it a second time, you're adding "2" to "user1" to produce "user12."
when you run through it a third time, you're adding "3" to "user12" to produce "user123."

rather than change txtuser.text AND lbluser.caption, why don't you only change lbluser.caption and leave txtuser.text alone? that way only your output (user1, user2) changes and not your input (user).

something like this:

count = count + 1
lbluser.Caption = txtuser.Text & count

this way, txtuser.text always stays the same, and lbluser.caption constantly changes to reflect the current numerical username.
chepfaust is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC