|
-
Jun 27th, 2008, 06:25 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [02/03] Code not working (numbers between forms)
Hi everyone,
Just a simple question, I've been trying to figure out why my code is not working for a particular number. What I want to do is take the highest number from a row in my datagrid and take that number into another row, well I have got the value in a datagrid but when I take it to the next form its shown as 1. However other values work fine (so when I take them to the same form the values are correct). What I'm trying to do is take the value to form2 and +1 to the value.
My coding is as follows:
Code:
'In the module
Friend Plusone As Integer
'To get the highest number from the row in a label
Dim conn As New OleDbConnection(String.Concat("Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & Application.StartupPath & "\CNS.mdb"))
Dim Cmd As New OleDbCommand("Select MAX(LogNumber) FROM Log; ", conn)
conn.Open()
lblnext.Text = Cmd.ExecuteScalar.ToString
conn.Close()
'Form2 Button
frm2.lblnext.Text = Me.lblnext.Text
Form2 Load Event
lblnext.Text = Plusone.ToString + 1
No matter what I do the value in that label is always 1. Any help or suggestions welcome.
-
Jun 27th, 2008, 06:41 PM
#2
Re: [02/03] Code not working (numbers between forms)
seems you forgot to assign value to Plusone variable in between
Code:
Friend Plusone As Integer
'you code
lblnext.Text = Plusone.ToString + 1
__________________
Rate the posts that helped you 
-
Jun 27th, 2008, 07:05 PM
#3
Thread Starter
Fanatic Member
Re: [02/03] Code not working (numbers between forms)
Hi,
I dont think thats the problem as other values are shown in the 2nd form and their values are +1, it seems to me there is something stopping this value from being +1. Could it be because I took it from a database
-
Jun 27th, 2008, 10:41 PM
#4
Re: [02/03] Code not working (numbers between forms)
And why would it not be? Where do you ever assign a value to Plusone? You don't therefore it's value is always zero. This line:
vb.net Code:
lblnext.Text = Plusone.ToString + 1
takes the value of Plusone, which is zero, and adds 1 to it. By my estimation that will always be 1. If you had debugged your code you would have seen this for yourself. Debugging is not just reading your code. It's running it and watching it in action, using breakpoints and the myriad other tools included in the VS debugger.
That line is also a bit of an abomination. You are taking an Integer, explicitly converting it to a String, then implicitly converting it back to an Integer, adding it to another Integer, then implicitly converting the result to a String. It should be this:
vb.net Code:
lblnext.Text = (Plusone + 1).ToString()
That takes an Integer and adds it to another Integer, then explixitly converts the result to a String. If you turn Option Strict On then code like yours will not compile and you'll be forced to write conversions properly.
-
Jun 28th, 2008, 02:28 AM
#5
Thread Starter
Fanatic Member
Re: [02/03] Code not working (numbers between forms)
Can't believe I didn't notice that, I actually deleted tha tline myself - embarassing to be honest.
Thanks for spotting that out guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|