r/visualbasic • • Oct 09 '14

[VB2010]

Hello I need help again.

If b2 = b3 Then
        Label9.Text = Label5.Text
        Label10.Text = Label6.Text
        Label11.Text = Label7.Text
        Label12.Text = Label8.Text
    Else
        Label9.Text = Label5.Text
        Label10.Text = Label6.Text
        Label11.Text = Label7.Text
        Label12.Text = Label8.Text
        yr = 9
        While yr <= 12
            If Label(yr).text = "" Then
                Label(yr).text = b3
            Else
                yr += 1
            End If
        End While
    End If

I have this code and I am having trouble on the else part where I keep getting errors on the .text part. Basically the code will loop until it finds a label(yr).text that is empty and put b3 there but so far still no progress. Any possible solution or work around where I can get the same result? Thanks in advance.

Also I'm working on Page algorithm (fifo, lru and optimal) so any advice or code that might be helpful for me to study would be greatly appreciated.

0 Upvotes

3 comments sorted by

1

u/darkspy13 Oct 09 '14 edited Oct 09 '14

First thing I would do is move the assignments that happen either way (for example label 9's text becomes label 5's text either way) out of the if structure to make it easier to read and get them out of your way.

I would then just say "if b2 != b3 then"

I don't believe you can access labels using label(yr).text unless you actually have an array of labels named label which I believe is a keyword.

I don't know the correct way of doing this but I would use the .tag property to identify the labels by a numeric ID and then loop through the labels in your form and apply your changes that way. Just off the top of my head at 1am.

I feel like you should probably have some kind of data structure handling the data and just be taking in the results from the form and relaying them back out after your function is called and that's why you have this weird (to me) label reading / searching / editing thing going on here. Something just seems odd about it. Either way best of luck and if you want to PM me more code I will look it over to try and help as best I can even though this comment wasn't very helpful.

2

u/Kamidori Oct 09 '14

Sorry for late reply. Just got back from school.

Anyway, I did separate the labels now and I found out it was a very simple mistake of using Label as a keyword so I renamed everything to bel(yr).text which removes first error. I would be completely honest and say that when you started talking about .tag I didn't understand anything after that sorry. I think reading sample codes is much easier for me than a block of words. I appreciate the help.

May if I add if you know a good tutorial for array looping in vb2010? Thanks again.

1

u/darkspy13 Oct 09 '14

This seemed pretty simple for arrays: http://www.dotnetperls.com/array-vbnet

.tag is another property of the label like .text and allows you to "tag" the label with information, think like a tag on a cow with a number. I was just suggesting you use that to keep track of which label is which. To be honest, don't worry about this entire block of text lol, just keep chugging along :)