What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » N00bish VB question

Pages: (2): « First [ 1 ] 2 » Last »
N00bish VB question
Author: Message:
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
33 / Male / Flag
Joined: Oct 2003
O.P. Tongue  N00bish VB question
I'm very new to Visual Basic and I'm making a program that displays text after text in a label when you click a button...but the only code I know is how to make a text in a label change once...like this;
code:
Private Sub Command1_Click()
Label1.Caption = "First Text"
End Sub

Could someone tell me the code to make the text change once again when the button's pressed again...

This post was edited on 06-04-2004 at 02:51 PM by Anubis.
[Image: anubis5hq.png]
06-04-2004 02:51 PM
Profile PM Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
RE: N00bish VB question
my gay way

[code]
Private Sub Command1_Click()
if Label1.Caption = "First Text" then
Label1.Caption = "2nd Text"
elseif Label1.Caption = "2nd Text" then
Label1.Caption = "First Text"

End Sub
06-04-2004 02:58 PM
Profile PM Web Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
33 / Male / Flag
Joined: Oct 2003
O.P. RE: N00bish VB question
What about adding like 20 bits of text...which I need to do for this ap
PS. That code seems to be invalid when I try and play it I get an error

This post was edited on 06-04-2004 at 03:04 PM by Anubis.
[Image: anubis5hq.png]
06-04-2004 03:01 PM
Profile PM Find Quote Report
Stigmata
Veteran Member
*****



Posts: 3520
Reputation: 45
20 / Other / Flag
Joined: Jul 2003
RE: N00bish VB question
:S

that method...but loads of it
06-04-2004 03:03 PM
Profile PM Web Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
33 / Male / Flag
Joined: Oct 2003
O.P. RE: N00bish VB question
quote:
Originally posted by jackass_wanabe
that method...but loads of it
You sure that's there's no more direct method?
[Image: anubis5hq.png]
06-04-2004 03:05 PM
Profile PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: N00bish VB question
declare a global variable (outside any function or sub you put the declaration)
code:
Dim times as long
in the load sub of the form, make sure you initializa that variable to the proper number, 0 for example)
code:
private sub form1_load()
  ' more code
   times=0
end sub

and in the button click sub, you put this code:
code:
private sub button1_click()
   times=times+1'the user clicked the button once more
   select case times
         case 1 ' 1st time the button is clicked
                label1.caption="1st text"
         case 2 ' 2nd time the button is clicked
                label1.caption="2nd text"
         case 3 ' 3rd time the button is clicked
                label1.caption="3rd text"
          ' etc....
         case else ' all the other cases (ie: from the last click you have coded)
                 label1.caption="you've clicked the button more times than what I was expected and didn't coded any other text to be displayed .p"
     end select
end sub



there are other ways to do that too. If the texts to be displayed are always the same, you can create an array of text and use the times variable to access the proper text (label1.caption=label1_texts[times])

This post was edited on 06-04-2004 at 03:12 PM by Choli.
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
06-04-2004 03:10 PM
Profile PM Find Quote Report
Sk3tch
Veteran Member
*****

Avatar
We are Samurai, the keyboard cowboys

Posts: 1675
Reputation: 4
38 / Male / –
Joined: Jul 2003
RE: N00bish VB question
quote:
Originally posted by Anubis
quote:
Originally posted by jackass_wanabe
that method...but loads of it
You sure that's there's no more direct method?
Yes.. use the case method :P
quote:
Originally posted by Anubis
PS. That code seems to be invalid when I try and play it I get an error
Make sure all the control names are the same.. ect..
Sk3tch@Microsoft.com - Email
- 53 6B 33 74 63 68 34 64@hotmail.com - Messenger
06-04-2004 03:10 PM
Profile E-Mail PM Web Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
33 / Male / Flag
Joined: Oct 2003
O.P. RE: N00bish VB question
quote:
Originally posted by Sk3tch
Yes.. use the case method
case method? What's that?
[Image: anubis5hq.png]
06-04-2004 03:12 PM
Profile PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: N00bish VB question
quote:
Originally posted by Anubis
quote:
Originally posted by Sk3tch
Yes.. use the case method
case method? What's that?
what I've just posted ;):P
code:
select case -----
    case -----
    case -----
    case -----
    case else
end select

Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
06-04-2004 03:16 PM
Profile PM Find Quote Report
Anubis
Elite Member
*****

Avatar
42

Posts: 2695
Reputation: 64
33 / Male / Flag
Joined: Oct 2003
O.P. RE: N00bish VB question
It doesn't seem to be working...I had to change it slightly because my version of VB uses slightly different codes;
code:
Private Sub Label1_load()
   times = 3
End Sub

Private Sub Command1_Click()
   times = times + 1 'the user clicked the button once more
   Select Case times
         Case 1 ' 1st time the button is clicked
                Label1.Caption = "1st text"
         Case 2 ' 2nd time the button is clicked
                Label1.Caption = "2nd text"
         Case 3 ' 3rd time the button is clicked
                Label1.Caption = "3rd text"
          ' etc....
         Case Else ' all the other cases (ie: from the last click you have coded)
                 Label1.Caption = "you've clicked the button more times than what I was expected and didn't coded any other text to be displayed .p"
     End Select
End Sub
3 times As Long
[Image: anubis5hq.png]
06-04-2004 03:21 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On