|
can you please help me with code in vb.net
|
|
|
|
|
you'll have to modify this code to suit your needs, but this is how I sort/merge text files.
m& = LBOUND(Master)
s& = LBOUND(Slave)
t& = 0
DO
IF m& < MasterLines& THEN '* aka not eof(masterfile%)
IF s& < SlaveLines& THEN '* aka not eof(slavefile%)
IF Master(m&) > Slave(s&) THEN '* reached end of primary so flush secondary
printToFile Slave(s&), OChannel%, s&, t&
ELSE
printToFile Master(m&), OChannel%, m&, t&
END IF
ELSE
printToFile Master(m&), OChannel%, m&, t&
END IF
ELSE
IF s& < SlaveLines& THEN
printToFile Slave(s&), OChannel%, s&, t&
ELSE
EXIT DO
END IF
END IF
LOOP
CLOSE OChannel%
PRINT MasterLines& " lines merged from Master file "; Mast$
PRINT SlaveLines& " lines merged from Slave file "; Slav$
PRINT t& " Records written to "; OutPF$
DO
LOOP UNTIL INKEY$ > ""
SYSTEM
SUB printToFile (x$, channel%, RecsPrinted&, t&)
t& = t& +1 '* increment the appropriate array counter
RecsPrinted& = RecsPrinted& + 1 ' keep track of how many processed so far
PRINT #channel%, x$
END SUB
SUB MergeSort (array() AS STRING, start&, finish&)
IF start& < finish& THEN '* no need to do this for 0-sized sublists
length& = finish& - start& + 1
middle& = start& + (finish& - start&) \ 2
MergeSort array(), start&, middle&
MergeSort array(), middle& + 1, finish&
REDIM temp(0 TO length& - 1) AS STRING
FOR i& = 0 TO length& - 1
temp(i&) = array(start& + i&)
NEXT
mptr& = 0
sptr& = middle& - start& + 1
FOR i& = 0 TO length& - 1
IF sptr& > finish& - start& THEN
array(i& + start&) = temp(mptr&)
mptr& = mptr& + 1
ELSE
IF mptr& > middle& - start& THEN
array(i& + start&) = temp(sptr&)
sptr& = sptr& + 1
ELSE
IF temp(mptr&) > temp(sptr&) THEN
array(i& + start&) = temp(sptr&)
sptr& = sptr& + 1
ELSE
array(i& + start&) = temp(mptr&)
mptr& = mptr& + 1
END IF
END IF
END IF
NEXT
ERASE temp
END IF
END SUB
|
|
|
|
|
Hi, its been years i don't do vb. So its like im a junior in this. I have problem update my Gridview. My gridview is to update marks for student. The problem is, the update have problem if the textbox is with a NULL value. If i put 0 in the textbox, the update runs ok.
This is my gridview html
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
<Columns>
<asp:TemplateField HeaderText="Student ID" SortExpression="stID">
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Width="50px" Text='<%# Bind("stID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO1" SortExpression="CO1">
<ItemTemplate>
<asp:TextBox ID="Label1" runat="server" Width="50px" Text='<%# Bind("CO1") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO2" SortExpression="CO2">
<ItemTemplate>
<asp:TextBox ID="Label2" runat="server" Width="50px" Text='<%# Bind("CO2") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO3" SortExpression="CO3">
<ItemTemplate>
<asp:TextBox ID="Label3" runat="server" Width="50px" Text='<%# Bind("CO3") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO4" SortExpression="CO4">
<ItemTemplate>
<asp:TextBox ID="Label4" runat="server" Width="50px" Text='<%# Bind("CO4") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO5" SortExpression="CO5">
<ItemTemplate>
<asp:TextBox ID="Label5" runat="server" Width="50px" Text='<%# Bind("CO5") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO6" SortExpression="CO6">
<ItemTemplate>
<asp:TextBox ID="Label6" runat="server" Width="50px" Text='<%# Bind("CO6") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO7" SortExpression="CO7">
<ItemTemplate>
<asp:TextBox ID="Label7" runat="server" Width="50px" Text='<%# Bind("CO7") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO8" SortExpression="CO8">
<ItemTemplate>
<asp:TextBox ID="Label8" runat="server" Width="50px" Text='<%# Bind("CO8") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO9" SortExpression="CO9">
<ItemTemplate>
<asp:TextBox ID="Label9" runat="server" Width="50px" Text='<%# Bind("CO9") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CO10" SortExpression="CO10">
<ItemTemplate>
<asp:TextBox ID="Label10" runat="server" Width="50px" Text='<%# Bind("CO10") %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BorderColor="Maroon" BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:UTMConnectionString %>"
SelectCommand="SELECT [stID], [CO1], [CO2], [CO3], [CO4], [CO5], [CO6], [CO7], [CO8], [CO9], [CO10] FROM [quiz] WHERE ([Cid] = @Cid)">
<SelectParameters>
<asp:SessionParameter Name="Cid" SessionField="CourseID" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
The erros is on line:
Quote: Dim C1 As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
This error will happen if i didn't put any values in the text box.. The error will be:
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +205
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +101
[InvalidCastException: Conversion from string "" to type
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +259
My button to update my gridview..
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim rowcollect As GridViewRowCollection = GridView1.Rows
Dim index As Integer = GridView1.SelectedIndex
Dim cd As String = Session("CourseID")
Dim id As String = Session("userID")
Dim totQuiz, totC1, totC2, totC3, totC4, totC5 As Integer
Dim totC6, totC7, totC8, totC9, totC10 As Integer
For Each row As GridViewRow In rowcollect
Dim C1 As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C2 As Integer = DirectCast(row.FindControl("Label2"), TextBox).Text
Dim C3 As Integer = DirectCast(row.FindControl("Label3"), TextBox).Text
Dim C4 As Integer = DirectCast(row.FindControl("Label4"), TextBox).Text
Dim C5 As Integer = DirectCast(row.FindControl("Label5"), TextBox).Text
Dim C6 As Integer = DirectCast(row.FindControl("Label6"), TextBox).Text
Dim C7 As Integer = DirectCast(row.FindControl("Label7"), TextBox).Text
Dim C8 As Integer = DirectCast(row.FindControl("Label8"), TextBox).Text
Dim C9 As Integer = DirectCast(row.FindControl("Label9"), TextBox).Text
Dim C10 As Integer = DirectCast(row.FindControl("Label10"), TextBox).Text
Dim sID As String = DirectCast(row.FindControl("Label11"), Label).Text
If row.RowType = DataControlRowType.DataRow Then
If index = -1 Then
index = 0
End If
For i As Integer = 1 To row.Cells.Count - 1
Dim conn As New SqlConnection(ConfigurationManager.AppSettings("strConn"))
Dim MySQL As String = "UPDATE quiz SET CO1=@c1,CO2=@c2,CO3=@c3,CO4=@c4,CO5=@c5,CO6=@c6,CO7=@c7,CO8=@c8,CO9=@c9,CO10=@c10 WHERE CourseID=@cID AND stID=@id"
Dim cmd As SqlCommand = New SqlCommand(MySQL, conn)
cmd.Parameters.AddWithValue("@cID", cd.Trim)
cmd.Parameters.AddWithValue("@id", sID)
cmd.Parameters.Add(New SqlParameter("@c1", SqlDbType.Int, 4))
cmd.Parameters("@c1").Value = Convert.DBNull(C1)
totC1 += C1
cmd.Parameters.Add(New SqlParameter("@c2", SqlDbType.Int, 4))
cmd.Parameters("@c2").Value = C2
totC2 += C2
cmd.Parameters.Add(New SqlParameter("@c3", SqlDbType.Int, 4))
cmd.Parameters("@c3").Value = C3
totC3 += C3
cmd.Parameters.Add(New SqlParameter("@c4", SqlDbType.Int, 4))
cmd.Parameters("@c4").Value = C4
totC4 += C4
cmd.Parameters.Add(New SqlParameter("@c5", SqlDbType.Int, 4))
cmd.Parameters("@c5").Value = C5
totC5 += C5
cmd.Parameters.Add(New SqlParameter("@c6", SqlDbType.Int, 4))
cmd.Parameters("@c6").Value = C6
totC6 += C6
cmd.Parameters.Add(New SqlParameter("@c7", SqlDbType.Int, 4))
cmd.Parameters("@c7").Value = C7
totC7 += C7
cmd.Parameters.Add(New SqlParameter("@c8", SqlDbType.Int, 4))
cmd.Parameters("@c8").Value = C8
totC8 += C8
cmd.Parameters.Add(New SqlParameter("@c9", SqlDbType.Int, 4))
cmd.Parameters("@c9").Value = C9
totC9 += C9
cmd.Parameters.Add(New SqlParameter("@c10", SqlDbType.Int, 4))
cmd.Parameters("@c10").Value = C10
totC10 += C10
totQuiz = C1 + C2 + C3 + C4 + C5 + C6 + C7 + C8 + C9 + C10
cmd.Parameters.Add(New SqlParameter("@total", SqlDbType.Int, 4))
cmd.Parameters("@total").Value = totQuiz
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Next
End If
Next
totCO(totC1, totC2, totC3, totC4, totC5, totC6, totC7, totC8, totC9, totC10)
End Sub
I try to put value '0' if the text box = Null, but it didn't work.
Its been few days I've been trying to find answers. Hope someone can suggest any idea for me to solve this.
modified 31-Oct-12 7:11am.
|
|
|
|
|
zaimah wrote: I try to put value '0' if the text box = Null, but it didn't work.
Its been few days I've been trying to find answers. Hope someone can suggest any idea for me to solve this.
From
Dim C1 As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
To
Dim C1S As String = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = Convert.ToInt32(C1S)
That should do it
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
It didn't work with the same error. before this, the error is at:
Dim C1 As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
after i edit using your suggestion, the error is at:
Dim C1S As String = DirectCast(row.FindControl("Label1"), TextBox).Text
its as if it didn't even reach the convert part, the error occurred.. I have try similar method, trying to convert the value so that it can update the value Null to my table, but the error is still at the find control.. Is there something wrong with my coding at find control part? But the update is successful, except when the value is NULL..
This really gives me a headache.. Thanks for replying my question
Is there any solution?
|
|
|
|
|
zaimah wrote: its as if it didn't even reach the convert part, the error occurred..
Put a breakpoint there and find out if it does, or does not execute.
zaimah wrote: Is there something wrong with my coding at find control part?
That wouldn't change due to a value being empty, would it?
Didn't notice before, but you're looking for Label1 and casting it to a TextBox . Shouldn't that be a Label you're casting to?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
the name for textbox is Label1.. Sorry for the confusion
Originally, the gridview only have edit button for each row of data in gridview. So i change my gridview in html. I change all the label to textbox and bound the text box. So i would only have one button to update everything that i key-in in the gridview. After i change the label to textbox, lazy of me, im not changing the name of the previous label
Would that effect the coding? But i can update the data. The problem is only when one of the textbox is empty. If the textbox that i cast for C10 is empty, then the error would be on C10, not C1.
|
|
|
|
|
C1 seems to be always containing NULL ; from the code you pasted;
cmd.Parameters("@c1").Value = Convert.DBNull(C1)
Shouldn't that be an integer?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Not always. If C1-C5 have value, and C6 is empty, then the error would be on C6. The weird thing is, the error only occur at textbox that are empty. It runs OK when there's no empty textbox.
|
|
|
|
|
That's not weird; you'll have to verify the users' input. If the database does not allow empty values (which it obviously doesn't), then you need to eliminate those before executing the query. It's either checking each value, or modify the database.
..you could copy the example-line, and add something similar to each parameter
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Do u mean the example that u gave me:
Dim C1S As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = Convert.ToInt32(C1S)
I have try using this method. It didn't work. How to check the value 1st and if its Null, put '0' in it?
the one that i put convert.dbnull is one of my testing. sorry for the confusion.
Sorry, my english s not that good
|
|
|
|
|
zaimah wrote: Do u mean the example that u gave me:
Dim C1S As Integer = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = Convert.ToInt32(C1S) That's not the example I gave you - the one you shown here tries to assign a string to an integer. This was the example;
Dim C1S As String = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = Convert.ToInt32(C1S)
zaimah wrote: Sorry, my english s not that good
It's good enough; we're making progress
zaimah wrote: I have try using this method. It didn't work. How to check the value 1st and if its Null, put '0' in it?
The problem with the line is that it does multiple things at once; it contains multiple instructions. It get's easier if you divide it into smaller pieces, as smaller problems are easier to conquer.
So, first one needs to find the control. You already know how to do that;
Dim TextBoxC1 As TextBox = DirectCast(row.FindControl("TextBox1"), TextBox)
Then, put a breakpoint on that line, and make sure it can actually find the control. If it doesn't, it might generate an exception, claiming it's null .
Once you got the correct control, you get it's value. Keep in mind that textboxes (and labels) contain strings, and that an empty string might be equal to null again. For an integer, we'd do something like the example; Convert.ToInt32 will change a "null" to 0. If you're saving a string, you'd use Convert.ToString. So, the code would continue like this;
Dim TextBoxC1 As TextBox = DirectCast(row.FindControl("TextBox1"), TextBox)
Dim ValueC1 As String = Convert.ToString(TextBoxC1.Text)
Once you got that, you can check whether "ValueC1" is "null" or an actual value (and replace it if required).
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
i did like this
Dim C1S As TextBox = DirectCast(row.FindControl("TextBox1"), TextBox)
Dim C1 As Integer = Convert.ToInt32(C1S)
And the error is this:
[InvalidCastException: Unable to cast object of type
System.Convert.ToInt32(Object value) +18
How can this be? my textbox suppose to have number as input not string. So i used convert.int32. Is this the correct way?
|
|
|
|
|
You're right, it's better if we look at them one at a time. A word of warning btw; I'm not a webdeveloper, just leaning on some general VB-knowledge.
Exception means that it can't find the control. That has to be fixed first, before we can convert values.
Dim C1S As TextBox = DirectCast(row.FindControl("TextBox1"), TextBox)
Dim C1 As Integer = Convert.ToInt32(C1S)
As you can see, I'm looking for "TextBox1", which would have been "Label1" in your code. You already stated that you renamed it, so if you change it to the code below, it should find it;
Dim C1S As TextBox = DirectCast(row.FindControl("Label1"), TextBox)
Dim C1 As Integer = Convert.ToInt32(C1S)
Like you said, it's a textbox, just named "Label1". The line after that should not throw an error.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I did like your told me.. But the error is still the same.. I try to using this
Dim C1S As String = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = Integer.TryParse(C1S, C1)
It works... it can update even with null value textbox. But another probem happens.. All of my value turn as negative in my table.. If i enter 1, it will be -1 in my table..
|
|
|
|
|
TryParse is indeed preferred over Convert.ToInt32. Didn't you find it weird that you had to add C1 as a parameter? It's not returning an integer (a number) but a boolean (y/no). Now, if we cast the boolean to an integer, it'll be -1. Could you try the value "42"? If it returns -42, a sign will be wrong, but I'm expecting it to return -1 also.
This should work;
Dim C1 As Integer = 0
Integer.TryParse(C1S, C1)
..with the boolean indicating whether the conversion to an integer was successful or not (since the string can contain "Hello world", and might not be able to return a number). That could also be used like below;
Dim C1 As Integer
If Integer.TryParse(C1S, C1) Then
Else
End If
Out of curiosity; when did you start with programming?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
ok.. I'm in trouble rite now.. Suddenly it cannot update anything.. i have to submit this prgm tomorrow...
1st time i learn doing this kind of prgm last year.. but only did this once. after almost a year, i have to do this project because im studying rite now. I learn to do this in 2 weeks.
|
|
|
|
|
It WORKS... yayyyy.. if i put empty textbox it will put 0 to my table... THANK YOU A LOT my code would be like this ...
Dim C1S As String = DirectCast(row.FindControl("Label1"), TextBox).Text
Dim C1 As Integer = 0
Integer.TryParse(C1S, C1)
Can u pls explain to me how it works? I think i sleep with a smile on my face tonite.. Its 12midnite rite now at my place... I've been building this prgm learning to do it by google.. Cannot find anyone to teach so i turn to Google.. But when this error come out... I cannot find the solution in google... THANK YOU AGAIN
|
|
|
|
|
zaimah wrote: It WORKS..
Whehe, well done - read both posts after another.
zaimah wrote: Can u pls explain to me how it works?
The first instruction finds the control, casts it to a textbox, gets it's value from the Text-property and assigns it to a new variable with the name C1S. That's a whole lot of responsibilities on a single line.
The second line declares a new variable (of the integer type) and assigns '0' to it.
The third line then tries to assign a number to C1, based on the text that's in C1S.
zaimah wrote: <layer>I think i sleep with a smile on my face tonite..
Rightly so
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
try
if DirectCast(row.FindControl("Label1"), Textbox).Text is Nothing then
'Skip here
End If
Catch ex as exception
'It's Empty move to another control
end try
Hope this helps the idea is to check for a value before trying to use it.
|
|
|
|
|
hi, i have a problem of Index was outside the bounds of the array. i don't understand how to amend the existing solution in my case. anyone could help me? the message error is System.IndexOutOfRangeException {"Index was outside the bounds of the array. Below is the code & the error is at sixth last line(strTextOut = arrMicrosensor(intNum).strCode)
Public Function sensorWithinRange() As MicrosensorStruct()
Dim arrMicrosensor() As MicrosensorStruct '
Dim dblNearestStation As MicrosensorStruct '
Dim intStationCounter As Integer 'Counter for stations
Dim dblStationE As Double 'Easting coords of one station
Dim dblStationN As Double 'Northing coords of one station
Dim intNearestSensor As Integer '
Dim strNearestSensor() As String '
Dim intA, intB, IntMaxIndex As Integer '
Dim dblMaxValue As Double '
Dim sMax, sTemp As MicrosensorStruct '
Dim strTextOut As String '
Dim strArrColumns() As String 'Columns within 1 station record
Dim chrArrDelim() As Char = " ,".ToCharArray() 'File delimiter
Dim sReader As IO.StreamReader
Dim strRecord As String
intStationCounter = -1
intNearestSensor = 0
dblStationE = CDbl(txtEasting.Text)
dblStationN = CDbl(txtNorthing.Text)
sReader = IO.File.OpenText(txtFilename.Text)
strRecord = sReader.ReadLine()
strRecord = sReader.ReadLine()
Do While (Not sReader.EndOfStream)
strRecord = sReader.ReadLine()
intStationCounter = (intStationCounter + 1)
Loop
sReader.Close()
Dim intNrStations As Integer 'Total number of station
ReDim arrMicrosensor(intNrStations)
sReader = IO.File.OpenText(txtFilename.Text)
strRecord = sReader.ReadLine()
dblNearestStation.dblRngeDist = Double.PositiveInfinity
For intStationCounter = 0 To intNrStations - 1
strRecord = sReader.ReadLine()
strArrColumns = strRecord.Split(chrArrDelim)
arrMicrosensor(intStationCounter).lngID = CLng(strArrColumns(0))
arrMicrosensor(intStationCounter).strOUTCORP = strArrColumns(1)
arrMicrosensor(intStationCounter).strCode = strArrColumns(2)
arrMicrosensor(intStationCounter).dblNorthing = CDbl(strArrColumns(3))
arrMicrosensor(intStationCounter).dblEasting = CDbl(strArrColumns(4))
arrMicrosensor(intStationCounter).dblRngeDist = CalculateDistance(dblStationN, dblStationE, arrMicrosensor(intStationCounter).dblNorthing, arrMicrosensor(intStationCounter).dblEasting)
If arrMicrosensor(intStationCounter).dblRngeDist &lt; CDbl(txtRangeDist.Text) Then
intNearestSensor = intNearestSensor + 1
'string for text in listbox
lboNearestStation.Items.Add("STATION ID:" &amp; arrMicrosensor(intStationCounter).lngID.ToString &amp; " , " _
&amp; "REFERENCE CODE:" &amp; arrMicrosensor(intStationCounter).strCode &amp; " , NORTHING:" _
&amp; arrMicrosensor(intStationCounter).dblNorthing.ToString("F") &amp; ", EASTING:" _
&amp; arrMicrosensor(intStationCounter).dblEasting.ToString("F") &amp; ", at:" _
&amp; arrMicrosensor(intStationCounter).dblRngeDist.ToString("F") &amp; "m")
End If
Next intStationCounter
sReader.Close()
ReDim strNearestSensor(intNearestSensor - 1)
For intStationCounter = 0 To intNrStations - 1
If arrMicrosensor(intStationCounter).dblRngeDist &lt; CDbl(txtRangeDist.Text) Then
intNearestSensor = 0
strNearestSensor(intNearestSensor) = arrMicrosensor(intStationCounter).strCode
End If
Next
Dim intNum As Integer
intNum = CInt(txtNrSensor.Text)
'For intNum = 0 To intNum - 1
For intNum = 0 To intNum - 1
For intA = arrMicrosensor.GetUpperBound(0) To 1 Step -1
sMax = arrMicrosensor(0)
dblMaxValue = sMax.dblRngeDist
IntMaxIndex = 0
For intB = 0 To intA
If arrMicrosensor(intB).dblRngeDist &gt; dblMaxValue Then
dblMaxValue = arrMicrosensor(intB).dblRngeDist
IntMaxIndex = intB
End If
Next intB
sTemp = arrMicrosensor(intA)
arrMicrosensor(intA) = arrMicrosensor(IntMaxIndex)
arrMicrosensor(IntMaxIndex) = sTemp
Next intA
strTextOut = arrMicrosensor(intNum).strCode
Next intNum
Return arrMicrosensor
End Function
modified 13-Oct-12 1:40am.
|
|
|
|
|
For intNum = 0 To intNum - 1
What do you expect to happen when the index reaches -1?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'm a hobbyist programmer, and sometimes I go many months without programming. I have recently come back to a project I started months ago, and I am confused by my own (working) code.
Here's the code that is confusing me:
Dim groupToAdd As DavisGroup
groupToAdd = Aggregate g In groupList Into FirstOrDefault(g.Name = newGroupName)
The variable groupList is a ListOf(DavisGroup). The code is testing to see whether the list already contains an object with the Name (String property of DavisGroup) "newGroupName" as the names have to be unique. My code goes on to do something different depending on if groupToAdd is a returned object or is Nothing. What I don't get is what "Aggregate" is doing.
In trying to search for an answer, I rewrote the same code like this:
groupToAdd = groupList.FirstOrDefault(Function(g) g.Name = newGroupName)
As far as I can tell, this code works in exactly the same way.
My questions:
What is Aggregate doing in this particular snippet?
Are these two snippets equivalent?
If so, is there a reason to prefer one over the other?
|
|
|
|
|
|
Employee ID :
Customer ID :
Order Date :
Shipped Date :
Shipper ID :
Ship Name :
Ship Address :
Ship City :
Ship State/Province :
Ship ZIP/Postal Code :
Ship Country/Region :
Shipping Fee :
Taxes :
Payment Type :
Paid Date :
Notes :
Tax Rate :
Tax Status :
Status ID :
<%
Dim Employee_ID, Customer_ID, Order_Date, Shipped_Date, Shipper_ID, Ship_Name,
Ship_Address, Ship_City, Ship_State_Province, Ship_ZIP_Postal_Code, Ship_Country_Region,
Shipping_Fee, Taxes, Payment_Type, Paid_Date, Notes, Tax_Rate, Tax_Status, Status_ID
Dim sConnString, connection, sSQL
Employee_ID=Request.Form("Employee_ID")
Customer_ID=Request.Form("Customer_ID")
Order_Date=Request.Form("Order_Date")
Shipped_Date=Request.Form("Shipped_Date")
Shipper_ID=Request.Form("Shipper_ID")
Ship_Name=Request.Form("Ship_Name")
Ship_Address=Request.Form("Ship_Address")
Ship_City=Request.Form("Ship_City")
Ship_State_Province=Request.Form("Ship_State_Province")
Ship_ZIP_Postal_Code=Request.Form("Ship_ZIP_Postal_Code")
Ship_Country_Region=Request.Form("Ship_Country_Region")
Shipping_Fee=Request.Form("Shipping_Fee")
Taxes=Request.Form("Taxes")
Payment_Type=Request.Form("Payment_Type")
Paid_Date=Request.Form("Paid_Date")
Notes=Request.Form("Notes")
Tax_Rate=Request.Form("Tax_Rate")
Tax_Status=Request.Form("Tax_Status")
Status_ID=Request.Form("Status_ID")
sSQL = "INSERT INTO Orders (Employee_ID, Customer_ID, Order_Date, Shipped_Date,
Shipper_ID, Ship_Name, Ship_Address, Ship_City, Ship_State_Province,
Ship_ZIP_Postal_Code, Ship_Country_Region, Shipping_Fee, Taxes, Payment_Type, Paid_Date,
Notes, Tax_Rate, Tax_Status, Status_ID) Values (" & Employee_ID & ", " & Customer_ID & ",
#" & Order_Date & "#, #" & Shipped_Date & "#, " & Shipper_ID & ", '" & Ship_Name & "', '"
& Ship_Address & "', '" & Ship_City & "', '" & Ship_State_Province & "', '" &
Ship_ZIP_Postal_Code & "', '" & Ship_Country_Region & "', '' & Shipping_Fee & '', '' &
Taxes & '', '" & Payment_Type & "', #" & Paid_Date & "#, '" & Notes & "', '" & Tax_Rate &
"', '" & Tax_Status & "', '" & Status_ID & "')"
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath
("/database/Examen.mdb")
Set connection = Server.CreateObject("ADODB.Connection")
connection.Open(sConnString)
connection.execute(sSQL)
response.write "The form information was inserted successfully."
connection.Close
Set connection = Nothing
%>
I have an HTML Form that request various data types and I keep getting the following error:
Microsoft JET Database Engine error '80040e10'
No value given for one or more required parameters.
/ordersconnection3.asp, line 32
It's a Microsoft Access Database. Any help will be appreciated.
|
|
|
|
|