|
-
Jan 3rd, 2010, 04:05 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] How to put 5 numbers in this order 1,2,3,4,5
i have 6 textboxes and i want the results of theses (1-2,1-3,1-4,1-5) to drive them
1 in 5 labels but the smallest result to label1 the second result to label2.....and the bigest result to label5
2 the numbers to abs absolute
3 the equal numbers to appear once
thank you
memas
-
Jan 3rd, 2010, 09:31 AM
#2
Re: How to put 5 numbers in this order 1,2,3,4,5
you have 6 numbers that you want to display in 5 labels???
to sort your numbers, add them to an array:
vb Code:
dim intArray() as integer = {5,3,2,4,1}
array.sort(intArray)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 12:13 PM
#3
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
i am new in programming and i cannot understand except if i send you the code that i have and you add the next step
thank you
memas
-
Jan 3rd, 2010, 12:16 PM
#4
Re: How to put 5 numbers in this order 1,2,3,4,5
post your code in this thread. use the Code or VBCode tags above the message editor textbox to format your code
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 03:40 PM
#5
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
Dim num1 As Integer = Val(num1TextBox.Text)
Dim num16 As Integer = Val(num16TextBox.Text)
Dim num17 As Integer = Val(num17TextBox.Text)
Dim num18 As Integer = Val(num18TextBox.Text)
Dim a As Integer = num1TextBox.Text - num16TextBox.Text
Dim b As Integer = num1TextBox.Text - num17TextBox.Text
Dim c As Integer = num1TextBox.Text - num18TextBox.Text
i want to drive theses results according to their values to labels the smallest label1 ,the bigest to label5
equal numbers to appear once
and the numbers to be abs absolute
-
Jan 3rd, 2010, 03:55 PM
#6
Re: How to put 5 numbers in this order 1,2,3,4,5
Code:
Option Strict On 'SHOULD BE FIRST STATEMENT OF ALL PROGRAMS
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tb1, tb2 As Integer 'Integer is one form of number.
'1. Make sure we have numbers. Check and convert the Textboxes(read about TryParse)
If Not Integer.TryParse(TextBox1.Text, tb1) Then
'what was in Textbox1 wasn't a number
Exit Sub
End If
If Not Integer.TryParse(TextBox2.Text, tb2) Then
'what was in Textbox2 wasn't a number
Exit Sub
End If
'2. Now that we have numbers we can subtract
Dim tb12diff As Integer
tb12diff = tb1 - tb2
'3. Now put that in a label
Label1.Text = tb12diff.ToString
End Sub
End Class
-
Jan 3rd, 2010, 04:00 PM
#7
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
i cannot understand the code what is the use of that
what means tb1
memas
-
Jan 3rd, 2010, 04:09 PM
#8
Re: How to put 5 numbers in this order 1,2,3,4,5
You would do yourself a great service by getting a fundamental book.
http://search.yahoo.com/search?p=vis...8&fr=yfp-t-701
-
Jan 3rd, 2010, 04:11 PM
#9
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
-
Jan 3rd, 2010, 04:15 PM
#10
Re: How to put 5 numbers in this order 1,2,3,4,5
Sorry. But
Dim something as Integer is fundamental, at least IMHO it is.
-
Jan 3rd, 2010, 04:16 PM
#11
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
-
Jan 3rd, 2010, 04:22 PM
#12
Re: How to put 5 numbers in this order 1,2,3,4,5
you've only given me 4 numbers to work with. but:
vb Code:
Dim num1 As Integer = Val(num1TextBox.Text)
Dim num16 As Integer = Val(num16TextBox.Text)
Dim num17 As Integer = Val(num17TextBox.Text)
Dim num18 As Integer = Val(num18TextBox.Text)
Dim a As Integer = math.abs(num1 - num16)
Dim b As Integer = math.abs(num1 - num17)
Dim c As Integer = math.abs(num1 - num18)
dim numbers() as integer = {a, b, c}
array.sort(numbers)
label1.text = numbers(0)
label2.text = numbers(1)
label3.text = numbers(2)
there are plenty of online resources + tuition available for beginners.
try this:
http://www.homeandlearn.co.uk/NET/vbNET.html
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 04:25 PM
#13
Re: How to put 5 numbers in this order 1,2,3,4,5
 Originally Posted by dbasnett
Sorry. But
Dim something as Integer is fundamental, at least IMHO it is.
booya!
if he'd got past the integer declaration the integer.tryparse would've got him
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 04:44 PM
#14
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
thank you very much
it is working except that we need equal numbers to appear once
and i have errors when the strict option is on
and how you describe this code are this an array?
i have a book from jame foxall that i read and i am in programming 15 days ago
memas
Last edited by memas; Jan 3rd, 2010 at 04:47 PM.
-
Jan 3rd, 2010, 04:57 PM
#15
Re: How to put 5 numbers in this order 1,2,3,4,5
this is an array:
dim numbers() as integer = {a, b, c}
its got 3 elements - 0, 1, + 2 which represent a, b, + c
heres another array, where its sorted differently + only distinct numbers (no more than 1 occurence of any number) are selected:
vb Code:
Dim numbers() As Integer = {2, 2, 4, 5, 5, 3, 1}
Dim distinctNumbers = (From item In numbers _
Order By item _
Select item Distinct)
numbers = distinctNumbers.ToArray
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 05:00 PM
#16
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
so which is the correct for my program?
memas
-
Jan 3rd, 2010, 05:05 PM
#17
Re: How to put 5 numbers in this order 1,2,3,4,5
a combination of the 2 posts
use the array from the first post, + the sorting + selecting from the last post.
as dbasnett said, you really need to read + practice with programming yourself to learn it.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 05:05 PM
#18
Re: How to put 5 numbers in this order 1,2,3,4,5
Figures... I found some of his books online, and if you have the Sam's Teach Yourself .Net in 24 Hours, Data Types aren't covered until Hour 12.
-
Jan 3rd, 2010, 05:15 PM
#19
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
i try to expan with more labels and more textboxes and i have error may i send you the code?
thank you
-
Jan 3rd, 2010, 05:17 PM
#20
Re: How to put 5 numbers in this order 1,2,3,4,5
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 05:19 PM
#21
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
thank you
Option Strict Off
Public Class testform1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1 As Integer = Val(num1TextBox.Text)
Dim num16 As Integer = Val(num16TextBox.Text)
Dim num17 As Integer = Val(num17TextBox.Text)
Dim num18 As Integer = Val(num18TextBox.Text)
Dim num19 As Integer = Val(num19TextBox.Text)
Dim num20 As Integer = Val(num20TextBox.Text)
Dim a As Integer = Math.Abs(num1 - num16)
Dim b As Integer = Math.Abs(num1 - num17)
Dim c As Integer = Math.Abs(num1 - num18)
Dim d As Integer = Math.Abs(num1 - num19)
Dim f As Integer = Math.Abs(num1 - num20)
Dim numbers() As Integer = {a, b, c, d, f}
Array.Sort(numbers)
label1.Text = numbers(0)
Label2.Text = numbers(1)
Label3.Text = numbers(2)
label4.Text = numbers(3)
Label5.Text = numbers(4)
Label6.Text = numbers(5)
Label7.Text = numbers(6)
End Sub
End Class
-
Jan 3rd, 2010, 05:34 PM
#22
Re: How to put 5 numbers in this order 1,2,3,4,5
ok. you can turn option strict back on. turn option infer on too.
your array has 5 elements - a, b, c, d, f
that is 0 to 4.
so numbers(0) is ok, numbers(4) is ok, but numbers(6) is outside of the bounds of the array
vb Code:
Public Class testform1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim num1 As Integer = Val(num1TextBox.Text)
Dim num16 As Integer = Val(num16TextBox.Text)
Dim num17 As Integer = Val(num17TextBox.Text)
Dim num18 As Integer = Val(num18TextBox.Text)
Dim num19 As Integer = Val(num19TextBox.Text)
Dim num20 As Integer = Val(num20TextBox.Text)
Dim a As Integer = Math.Abs(num1 - num16)
Dim b As Integer = Math.Abs(num1 - num17)
Dim c As Integer = Math.Abs(num1 - num18)
Dim d As Integer = Math.Abs(num1 - num19)
Dim f As Integer = Math.Abs(num1 - num20)
Dim numbers() As Integer = {a, b, c, d, f}
Dim distinctNumbers = (From item In numbers _
Order By item _
Select item Distinct)
numbers = distinctNumbers.ToArray
if numbers.getupperbound(0) >= 0 then
label1.Text = numbers(0).tostring
else
label1.Text = ""
end if
if numbers.getupperbound(0) >= 1 then
Label2.Text = numbers(1).tostring
else
label2.Text = ""
end if
if numbers.getupperbound(0) >= 2 then
label3.Text = numbers(2).tostring
else
label3.Text = ""
end if
if numbers.getupperbound(0) >= 3 then
Label4.Text = numbers(3).tostring
else
label4.Text = ""
end if
if numbers.getupperbound(0) >= 4 then
Label5.Text = numbers(4).tostring
else
label5.Text = ""
end if
End Sub
End Class
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 05:42 PM
#23
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
the programe works but when i turn on the option strict i have errors
Option Strict On disallows implicit conversions from 'Double'
thank you again you are a god
-
Jan 3rd, 2010, 05:50 PM
#24
Re: How to put 5 numbers in this order 1,2,3,4,5
change:
to:
vb Code:
Math.Abs(cint(num1 - num16))
etc
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 05:55 PM
#25
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
i changed it but still errors
Option Strict On disallows implicit conversions from 'Double' to 'Integer'.
maybe is there that i write val(num1TextBox.Text)?
memas
cint(val(num1TextBox.Text)) returns an integer
and this works what is better?
'
Last edited by memas; Jan 3rd, 2010 at 06:02 PM.
-
Jan 3rd, 2010, 05:58 PM
#26
Re: How to put 5 numbers in this order 1,2,3,4,5
i found it now.
val(num1TextBox.Text) returns a double
cint(val(num1TextBox.Text)) returns an integer
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 06:00 PM
#27
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
paul
i tried this and works no errors
Dim num1 As Integer = Integer.Parse(num1TextBox.Text)
Dim num16 As Integer = Integer.Parse(num16TextBox.Text)
Dim num17 As Integer = Integer.Parse(num17TextBox.Text)
Dim num18 As Integer = Integer.Parse(num18TextBox.Text)
Dim num19 As Integer = Integer.Parse(num19TextBox.Text)
Dim num20 As Integer = Integer.Parse(num20TextBox.Text)
memas thank you again
-
Jan 3rd, 2010, 06:05 PM
#28
Re: How to put 5 numbers in this order 1,2,3,4,5
that works ok if your textbox contains an integer. if not it causes a runtime error.
try this:
vb Code:
Dim num1 As Integer
Integer.tryParse(num1TextBox.Text, num1)
Dim num16 As Integer
Integer.tryParse(num16TextBox.Text, num16)
Dim num17 As Integer
Integer.tryParse(num17TextBox.Text, num17)
Dim num18 As Integer
Integer.tryParse(num18TextBox.Text, num18)
Dim num19 As Integer
Integer.tryParse(num19TextBox.Text, num19)
Dim num20 As Integer
Integer.tryParse(num20TextBox.Text, num20)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 06:08 PM
#29
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
is better to choose the parse method or the cint ?
memas
-
Jan 3rd, 2010, 06:20 PM
#30
Re: How to put 5 numbers in this order 1,2,3,4,5
If you just use CInt and some one put a letter (a,b A....) in the text box the application will error. The TryParse avoids this condition
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jan 3rd, 2010, 06:22 PM
#31
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
-
Jan 3rd, 2010, 06:36 PM
#32
Re: How to put 5 numbers in this order 1,2,3,4,5
as gary said, CInt can cause an error
CInt("1") returns 1 in integer datatype
CInt("a") causes a runtime error
Val("1") returns 1 in double datatype
Val("a") returns 0 in double datatype
so
CInt(Val("1")) returns 1 in integer datatype
CInt(Val("a")) returns 0 in integer datatype
but integer.tryparse is a better option
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 3rd, 2010, 06:41 PM
#33
Thread Starter
Fanatic Member
-
Jan 3rd, 2010, 06:42 PM
#34
Re: How to put 5 numbers in this order 1,2,3,4,5
Now would be the best time to read about data types in your book.
-
Jan 3rd, 2010, 06:43 PM
#35
Thread Starter
Fanatic Member
Re: How to put 5 numbers in this order 1,2,3,4,5
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
|