Last post Aug 07, 2020 10:11 AM by raysilvatele
Aug 05, 2020 10:42 PM|ewallig|LINK
Hi, built this function:
Public Shared Function getAcCurr(ByVal varID, ByVal acType) As getAcCurrency
Dim getAcCurrVal As getAcCurrency
Dim dateNow As Date = Now()
Dim date90 As Date = dateNow.AddDays(-90)
Dim objConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyDB.My.MySettings.db_conn").ConnectionString)
Dim sSQL As String = "select aircraftType, SUM(dayLnd) as 'dayLnd', SUM(nightLnd) as 'nightLnd' from t_curtrack where currencyDate between '" & date90 & "' and '" & dateNow & "' and pic = '" & varID & "' and aircraftType = '" & acType & "' or currencyDate between
'" & date90 & "' and '" & dateNow & "' and sic = '" & varID & "' and sicFlewLeg = '1' and aircraftType = '" & acType & "' group by aircraftType"
Dim objCmd As New SqlDataAdapter(sSQL, objConn)
Dim DS As New DataSet()
If DS.Tables(0).Rows.Count > 0 Then
If Not IsDBNull(DS.Tables(0).Rows(0).Item("aircraftType")) Then
getAcCurrVal.acData1 = DS.Tables(0).Rows(0).Item("dayLnd")
getAcCurrVal.acData2 = DS.Tables(0).Rows(0).Item("nightLnd")
getAcCurrVal.acData1 = 0
getAcCurrVal.acData2 = 0
It has a supporting public structure and the function is nearly identical to another function that works correctly. Calling it from my code behind using code similar to this:
aircraftDay = Class1.getAcCurr(varID, "aircraftType") - varID is the staff member (pilot, etc) that I'm trying to return a count of day and night landings and "aircraftType" is a string that identifies the type of aircraft that we are looking to query.
I'm getting a "Conversion from type 'getAcCurrency' to type 'Integer' is not valid." in VS2019. Now I do this for another type of data that we are trying to query on the same page using an almost identical function and it works fine. The only difference
between the functions is the one that works only takes varID - it doesn't get the "aircraftType" variable.
I'm at a loss trying to figure this out - I've tried Cint() on various parts of both the function and in the code behind, etc...no joy...any help appreciated.
Aug 06, 2020 01:48 AM|Sean Fang|LINK
The function has no error itself. The problem might be that you tried to convert the function result, which is of type 'getAcCurrency', to the type 'Integer' in below codes (This is what I am guessing since the information
you provide is not sufficient):
aircraftDay = Class1.getAcCurr(varID, "aircraftType")
You might need to check if the variable aircraftDay's type is 'Integer'.
If so, you might need to modify the codes e.g. to fetch the integer value from the function result.
Hope this can help you.
Aug 06, 2020 12:43 PM|ewallig|LINK
Thanks for the reply - I have aircraftDay set as Integer (Dim aircraftDay as Integer = 0) at the top of the code behind. To add some info on how this is set up - this call runs inside of rowdatabound:
Dim gvr as GridViewRow = e.Row
if gvr.RowType = DataControlRowTpye.DataRow then
Dim varID as Integer = Databinder.Eval(gvr.DataItem, "id")
aircraftDay = Class1.getAcCurr(varID, "C182") 'Looking for data for a Cessna 182 in this example
'now do some math to see if the pilot is current
if aircraftDay >= 3 then
'do coloring in the GV
I'm doing this for a call to the other function (the one that is almost identical) and it works fine (also returns integers) but this one errors. Hope that sheds a little more light on what might be going on.
Aug 06, 2020 12:59 PM|PatriceSc|LINK
Yes aircraftDay is an integer and so aircraftDay = Class1.getAcCurr(varID, "C182") tries to assign a value whose type is getAcCurrency to an integer causing this message.
Assuming "aircraftDay" is the total number of landings it seems you want perhaps:
Dim data=Class1.getAcCurr(varID,"C182") ' This is just an object or structure that exposes multiple values, this is NOT an integer
aircraftDay=data.acData1+data.actData2 ' Add day and night landings integer values exposed by this object or structure
Edit: more likely our other function does return directly an integer but this is not for this one as it uses "As getAcCurrency" not "As Integer".
Aug 06, 2020 01:11 PM|ewallig|LINK
OK, so this is why I should not code after 300pm - I omitted the .public component when calling the class function :(
I had the following:
aircraftDay = Class1.getAcCurr(varID, "C182")
It needed to be:
aircraftDay = Class1.getAcCurr(varID, "C182).data1
Ugh, ok thanks for the help - still have a couple of bugs with the data being returned but not erroring anymore.
Aug 06, 2020 01:42 PM|PatriceSc|LINK
This is a runtime error?
You could consider using https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-strict-statement which
is less permissive (will catch some of these at compile time for the price of being explicit about the conversion you want in your code).
You don't have to do the switch in one go as this option could be set both at the project level and for each file (ie "On" at the global level, and "Off" at the file level would preserve the current behavior, then when working on a file you can take the
occasion to move a file from the "Off" to the "On" option).
Aug 06, 2020 01:49 PM|ewallig|LINK
Thanks but this literally was me not writing the full line of code to do the function call. The function uses a public structure and I had omitted the .data suffix (not the best word but hopefully it makes sense). As a result the function call was trying
to return the getAcCurr vs. getAcCurr.data1 - the .data1 being type "Integer" :|
Aug 07, 2020 10:11 AM|raysilvatele|LINK
Obrigado pela sua breve explicação me ajudou muito a tirar algumas dúvidas relacionadas a este tópico!