|
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.
|
|
|
|
|
It looks like you could be passing a null value to one of your columns. I would check that out first.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
I've tripled checked that all the Allow Zero Length field are on NO. Is there anything else I should be looking out for? Does the syntax look accordingly even for the currency field?
|
|
|
|
|
Does the sql string built above, with all the parameters, run from within the Access query builder?
|
|
|
|
|
I work for an ISP strictly for small business and minimal residential. We provide different services as well as web hosting. We have to convert web domains to an IP once a month from a list.
I am trying to recreate an app in VB.net and it takes forever for ping result to come back as true or flase and when I transl;ate the host into an IP it doesnt get an IP for the host even though it exists. Here is a sample picture of my compiled app running:
http://postimg.com/87000/what-86552.jpg[^]
my code in vb.net:
Imports System
Imports System.Net
Imports System.IO
Public Class Form1
Dim reachable As Boolean = False
Dim IPEntry As IPHostEntry
Dim ReadAllLinesArray() As String
Public Function IsDestinationRechable(ByVal hostOrAddress As String)
Try
reachable = My.Computer.Network.Ping(hostOrAddress)
Catch pingException As System.Net.NetworkInformation.PingException
Catch genericNetworkException As System.Net.NetworkInformation.NetworkInformationException
End Try
Return reachable
End Function
Public Sub GetPingAndIPv4()
Try
For Each s As String In ReadAllLinesArray
Try
IPEntry = Dns.GetHostByName(s)
If IsDestinationRechable(IPEntry.AddressList(0).ToString) = True Then
Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
lsv.SubItems.Add(IPEntry.AddressList(0).ToString)
lsv.SubItems.Add(IsDestinationRechable(reachable))
tssProgressBar.PerformStep()
Else
Dim lsv As ListViewItem = lsvHostItemList.Items.Add(s)
lsv.SubItems.Add("n/a")
lsv.SubItems.Add(IsDestinationRechable(reachable))
tssProgressBar.PerformStep()
End If
Catch ex As Exception
End Try
Next
Catch ex As Exception
End Try
End Sub
Private Sub OpenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles OpenToolStripMenuItem.Click
If OpenOldHostsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
ReadAllLinesArray = File.ReadAllLines(OpenOldHostsFile.FileName)
tssProgressBar.Maximum = ReadAllLinesArray.Count
End If
End Sub
Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
If SaveNewHostsFile.ShowDialog = Windows.Forms.DialogResult.OK Then
End If
End Sub
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub RunToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles RunToolStripMenuItem1.Click
GetPingAndIPv4()
End Sub
My code isn't complete I am trying to get the main functionality working correctly first.
|
|
|
|
|
The most common is your DNS infrastructure is taking forever to resolve the host name passed into the Ping method. There are anyn number of reasons for this, none which have anything to do with your code.
Also, the default timeout for Ping to wait for a response is half a second, so I hope you don't mean that takes forever.
|
|
|
|
|
I managed to figure out why, my next question is, why is my code not returning the IP and saying the site site is in active, and also when it returns an IP I type that IP in the browser and it doesn't take me to the domain that its assigned to. why? I guess I could see this as a security prevention but how do I get the right IP from it?
|
|
|
|
|
All of this comes down to a screwed up DNS system. None of this is because of your code.
If you give the DNS system host name and it returns the wrong IP, unless you're the administrator of the DNS system, there's nothing you can do about it.
Either the correct IP is returned, or some proxy server for the browser to use is returned, or the data doesn't go to the correct machine.
The other thing is that Ping is NOT a viable method for determining if a host is available or not. This is because firewalls may be between you and the host, blocking ICMP traffic or the host may be ignoring all ICMP traffic, even though the server and its web site are up and running and responding.
|
|
|
|
|
Knowing I dont have the admin access what would be the viable method without seeming I am a threat to any system. If ICMP isnt going to work then how else would I go about converting the hostname into an IP using the best methods?
|
|
|
|
|
Without a known good authoritative DNS that knows about the target system you have no options. The only thing you need the DNS for is to resolve the hostname to an IP or the other way around. If you don't have a good DNS, you have no hope of matching up hostnames to IPs.
ICMP is the protocol that Ping uses, not DNS. Ping sends an ICMP packet to the hostname or IP specified and waits for a response. If it gets one within the timeout period, the host is considered alive by Ping.
If not, this is in no way an indication that the host is unavailable or down. It just means the packet either never got to the host because of a firewall blocking it (getting more and more common) or it's passing through some hop that filters out ICMP.
Internally, Ping uses DNS to resolve a specified hostname to an IP. You can only talk to IP addresses, not hostnames. If DNS is wrong or not working properly, the Ping will be wrong too.
|
|
|
|
|
Perhaps a far-fetched alternative, but at least it's another option;
You could setup OpenDNS[^] on a remote machine, and have that convert the IP to a host-name (using a webservice or whatever type of communication). You'd call the <a href="http://msdn.microsoft.com/en-us/library/sbetxfzt.aspx">Dns.GetHostByAddress</a>[<a href="http://msdn.microsoft.com/en-us/library/sbetxfzt.aspx" target="_blank" title="New Window">^</a>] -member, and return the host-name.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|