|
-
Dec 15th, 2011, 02:57 PM
#1
Thread Starter
Addicted Member
-
Dec 15th, 2011, 03:19 PM
#2
Re: reading a mathematical operation
val + cint don't process mathematical operations in strings
but you can do this:
vb Code:
dim dt as new datatable
x=dt.compute(replace(label1.text,"y",i))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 15th, 2011, 04:42 PM
#3
Thread Starter
Addicted Member
Re: reading a mathematical operation
as it says a filter is required but i didnt understand the process so i dont know what to write as a filter
and also it says nulreference when i wrote this ...:
Code:
dt.Compute((Replace(Label1.Text, "k", i)), 100)
i couldnt understand this process also the whole new system.nullreferenceexception thing...:S
Last edited by ugur; Dec 15th, 2011 at 04:52 PM.
-
Dec 15th, 2011, 05:16 PM
#4
Re: reading a mathematical operation
vb Code:
x = dt.Compute(Replace(Label1.Text, "k", i), Nothing)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 15th, 2011, 06:13 PM
#5
Thread Starter
Addicted Member
Re: reading a mathematical operation
but its still says nullreference for dt
Code:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim i As Integer, array(CInt(en) - CInt(ka)) As Integer, ii As Integer, rslt As Integer, dt As DataTable
For i = CInt(ka) To CInt(en)
array(i - CInt(ka)) = dt.Compute((Replace(Label1.Text, "k", i)), Nothing)
Next
For ii = 0 To UBound(array)
rslt = rslt + array(ii)
Next
Label1.Text = CStr(rslt)
End Sub
End Class
here s my progress
-
Dec 15th, 2011, 07:16 PM
#6
Re: reading a mathematical operation
where do you declare dt?
try combining post #2 + post #4 + it'll work
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 17th, 2011, 01:58 AM
#7
Thread Starter
Addicted Member
Re: reading a mathematical operation
Code:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim i As Integer, array(CInt(en) - CInt(ka)) As Integer, ii As Integer, rslt As Integer
Dim dt As DataTable
For i = CInt(ka) To CInt(en)
array(i - CInt(ka)) = dt.Compute((Replace(Label1.Text, "k", i)), Nothing)
Next
For ii = 0 To UBound(array)
rslt = rslt + array(ii)
Next
Label1.Text = CStr(rslt)
End Sub
i already did but it s not working maybe for another reason
-
Dec 18th, 2011, 02:47 PM
#8
Thread Starter
Addicted Member
Re: reading a mathematical operation
do you understand why it says that ?
-
Dec 18th, 2011, 04:07 PM
#9
Thread Starter
Addicted Member
Re: reading a mathematical operation
-
Dec 21st, 2011, 05:24 PM
#10
Thread Starter
Addicted Member
Re: reading a mathematical operation
Code:
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
Dim i As Integer, array(CInt(en) - CInt(ka)) As Integer, ii As Integer, rslt As Integer
Dim dt As DataTable
dt = New DataTable
For i = CInt(ka) To CInt(en)
array(i - CInt(ka)) = dt.Compute((Replace(Label1.Text, "k", i)), Nothing)
Next
For ii = 0 To UBound(array)
rslt = rslt + array(ii)
Next
Label1.Text = CStr(rslt)
rslt = 0
End Sub
i got the problem but now it doesnt work well...
the solution isnt what i want it to be (en is 10 and ka is 1 i couldnt find a mistake but i dont know anything about the datatable classes so im not sure whats going on...
-
Dec 21st, 2011, 06:37 PM
#11
Re: reading a mathematical operation
I can't say that I'm thrilled with this line:
array(CInt(en) - CInt(ka))
If you are sure that en>ka, it will work ok, but you have to be sure.
As for the overall problem, what .Paul. suggested is certainly clever, but it seems kind of like a dead end. It will work for simple equations, but will get increasingly cumbersome as you increase the complexity of the equation. I assume that there is a point to this that requires the equation from the label, or else there is probably a better way to get to the end you want. I would say that a more complete explanation of the actual problem would result in a better solution.
As for it not working well, what does that mean? Are you getting the wrong answer, or is it just slow? If you are getting the wrong answer, then it is time to put a breakpoint on that first For loop and step through the code taking a look at what is happening with each step. If you haven't learned about breakpoints, then now is certainly the time to learn.
My usual boring signature: Nothing
 
-
Dec 21st, 2011, 06:47 PM
#12
Re: reading a mathematical operation
my guess is operator precedence. i.e:
vb Code:
MsgBox(1 + 2 * 5)
MsgBox((1 + 2) * 5)
give different answers
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Dec 22nd, 2011, 01:34 PM
#13
Thread Starter
Addicted Member
Re: reading a mathematical operation
@paul
thanks but its only k + 1 so there s no operator precedence
@shagy
dont worry about the array because i prevented the other oportunity...
and i meant it doesnt give the result that it should give...i get 1 instead of anything.. whatever i write i get 1....
-
Dec 22nd, 2011, 02:01 PM
#14
Thread Starter
Addicted Member
Re: reading a mathematical operation
i fixed it by the way i gues i forgot checking a code basically after a break...its just variable issues
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
|