Hey all, Under a button function is there anyway to implement an OR function? For example; Label1.Text = Button1 or Button2 or Button3 Seems to be "adding" the variables... I want it so that the label will read button 1, 2 or 3 depending on which one I click. any help?
What are you trying to get Label1.Text to say? If you click Button1, Label1.text take on the Button1.Caption? Easiest way is to Create one button, size it etc how you need then copy it and paste it back in. VB should ask if you want to create an array so say yes. Then copy and paste as many buttons in as you need and arrange as needed. Change the caption on each button to say what you want (i.e. "1" or "One" etc). Double click the button to give you a Sub for it and it goes something like this Code: Private Sub Button1_Click(Index As Integer) Label1.Text = Button1(Index).Caption End Sub I'll try and install VB if your struggling but thats how I'd do it in the first instance if I understand what your trying to do.
Thanks for the reply dynamis Ok, so I have 3 numbers stored in the buttons. If I select the 3rd button, I want that value to go into Label 1 If I select the 1st button, I want that value to go into Label 2 So basically, whenever I click a button, I want it to go in the corresponding label. So, label 1 being the first button I click, label 2 being the second and so on. - I tried the Label1 = Button1 or Button2 or Button3 hoping that if I selected button 1, 2 or 3 the value would be inserted into the label but it either adds it together or goes to the last term (button3). Also, Just tried what you mentioned but got a Caption is not a member of system.windows.forms.button Hope you can help...
when you say values stored in the button, do you mean the text that the button shows - like 'Click me' or in a number pad example would be 1-9 etc Ah, you using VB.net by any chance? I pretty much stopped programming with VB6 so I'm not familiar with VB.NET It maybe button.Text rather than caption. Afraid I haven't programmed Vb seriously in 7-8 years If you want to have the same amount of labels as buttons, you could create an array of labels too - then position themsto the label which is to take on button(0) value, is label1(0) then do something like Code: Label1(Index).Text = Button1(Index).Text
Hey Yes theyre numbers stored. I see what you are saying, but I dont want Label1.Text = Button1.Text I want it so that if I click the value in Button 3 first, it will display in Label1. Then if i click on Button1 second, it will display in Label2. So basically Label1, 2 and 3 are my 1st, 2nd and 3rd clicks of the button. If that makes sense?
Maybe lol. So kind of like a code entry type thing? So you want to be able to press any button in any order, and have the first press land in Label1, the 2nd to press in label2, the 3rd to press in label3 - but not always in the same order? disclaimer - sorry If I'm confusing things, I not 100% what your aiming at
Well based on you only carrying this out when the form loads up to start I would do something like: Create an array of buttons - in example above 3 in total Button1(0),Button1(1) & Button1(2) Create an array of labels - in example above 3 in total Label1(0), Label(1) & Label(2) dim CurrentLabelPosition as Integer - This will hold your count to see which label you are using in the form loading event set the current position to 0. This will be set your first label (label1(0)) as the first to be filled in with the button.text. Private Form_Load() CurrentLabelPosition = 0 End Sub This basically says when a button is pressed, used the CurrentLabelPosition variable to say which Label to use, then take the text of the button pressed and use it to popluate the Label.text value. Once the label has is text assigned, add one to the CurrentLabelPosition counter. Private Sub Button1_Click(Index As Integer) Label1(CurrentLabelPosition).Text = Button1(Index).Text CurrentLabelPosition = CurrentLabelPosition + 1 End Sub In the example of a code entry you could put an IF statement in the Button1_click sub to say if CurrentTablePosition = 2 then msgbox ("you got code right") Hope that make sense. Again code is off my head and untested
Thanks Dynamis! Works fine now Ran into another issue, hopefully someone can help.... Ok so I've now made 2 arrays. For example; Array One has 3, 2, 1 Array Two has 1, 2, 3 I want to be able to sort Array One in Ascending Order. Then say "If Array One = Array Two" MessageBox.Show("Well Done"). and if not equal, MessageBox.Show("Have another go"). - Problem I am coming across is I am coming across is that Array One will have the numbers mixed up. I'm trying to use the Array.Sort on the entire array. I'm trying to put, for example, SortedNumbers = Array.Sort(array1) But it gives the error "expression does not produce a value". Just wondered if anyone knows how I go about doing this?
I'm afraid I'm jut on my phone so can't give long answer - however are you familiar with the theory of the bubble sort? If not take a look as I see it being easiest way to sort the array unless VB.net have it built in.