Home > Net >  Vb.net parameter array problem
Vb.net parameter array problem

Time:11-14

I need to write a function, the return value is an array, the function of the parameter should be how to write, pass the arguments of how to write? How to match types and parameters

CodePudding user response:

Don't tangle back words how many strokes are there? "" The most basic things, self-study,

CodePudding user response:

reference 1st floor interacting in a professional developer response:
snarling "back words how many strokes are there?" The most basic things, self-study,

To explain

CodePudding user response:

I didn't understand you what is the relationship between the return value is an array and parameter
Function parameters only function to do have a relationship with you, such as an additive function parameter is two type int or other numeric types but return value can be any type I directly in the internal output doesn't need to return so the return value is void after need to know the addition of outside and I can return int double float long etc. Even if you against a string and then let out yourself to the transformation type

CodePudding user response:

reference 4 floor OrdinaryCoder response:
I didn't understand you what is the relationship between the return value is an array and parameter
Function parameters only function to do have a relationship with you, such as an additive function parameter is two type int or other numeric types but return value can be any type I directly in the internal output doesn't need to return so the return value is the void outside need to know and I can add after return int double float long etc. Even if you against a string and then let out to transform type
I want to achieve operation is to read the database table and then to deal with one of the column, and then will be displayed on the column in the listview, my way is to write a function, the data into the first datatable, then not a data in column B datatable. Row (I). The item/B_average (" B "), and then will get the number of columns is stored in arrays arr1, and then the number of columns in the listview display now write this function does not return arr1, and in a listview where calls to this function parameters also don't know what should write,, please the great god if you have time to help me solve the solution to this problem, thank you very much

CodePudding user response:

Function: why don't you let the return arr1? Does not define a return value? Public double [] function () {} you define like this?
What parameters? Parameters and return values have no relationship, and doesn't seem to need to see your demand parameters

CodePudding user response:

Your vb.net, the syntax is slightly different
 
Public Function Function name (parameters As Object) As a Double ()

Dim arr As a Double ()={1, 2, 3}

Return arr

End the Function

Parameters and parameters, the return value is the return value, or stick down your code, see your thought process

CodePudding user response:

refer to 7th floor HZTLTGG response:
your vb.net, the syntax is slightly different
 
Public Function Function name (parameters As Object) As a Double ()

Dim arr As a Double ()={1, 2, 3}

Return arr

End the Function

Parameters and parameters, the return value is the return value, or stick down your code, look at your ideas

Hello, I put the code, if you have time you can take a look at it for me,
Imports System. The Data. SqlClient

Public Class IntoArray
The Public Function SqlInput () As an Integer (,)
Dim conn As SqlConnection=New SqlConnection (DbConnstr connstring () 'create link object
Dim sqlStr As String="select * from test_data"
Dim CMD As SqlCommand=New SqlCommand (sqlStr, conn) 'create a command object
Dim da As SqlDataAdapter=New SqlDataAdapter (CMD)
Dim ds As New DataSet
Try
Conn. The Open ()
Da. The Fill (ds, "Dtable")
Catch the ex As Exception
Conn. Close ()
Throw New Exception (ex. Message)
The Finally
Conn. Close ()
End the Try
Dim B_max As Integer=Dtable.Com pute (" Max (B) ", "")
Dim B_min As Int32=Dtable.Com pute (" min (B) ", "")
Dim A_max As Int32=Dtable.Com pute (" Max (A) ", "")
Dim A_min As Int32=Dtable.Com pute (" min (A) ", "")
Dim D_max As Int32=Dtable.Com pute (" Max (D) ", "")
Dim D_min As Int32=Dtable.Com pute (" min (D) ", "")
Dim P_max As Int32=Dtable.Com pute (" Max (P) ", "")
Dim P_min As Int32=Dtable.Com pute (" min (P) ", "")
Dim B_average As Int32=(B_max - B_min)/5
Dim A_average As Int32=(A_max - A_min)/5
Dim D_average As Int32=(D_max - D_min)/5
Dim P_average As Int32=(P_max - P_min)/5
Dim arr1 (,) As Int32
For I=0 To Dtable. Rows. The Count - 1
If Dtable. Rows (I). The Item (" B ")/B_average & lt; 1 Then
20 * 0.4=arr1 (I, 1)
ElseIf Dtable. Rows (I). The Item (" B ")/B_average & lt; 2 Then
Arr1 (I, 1)=40 * 0.4
ElseIf Dtable. Rows (I). The Item (" B ")/B_average & lt; 3 Then
Arr1 (I, 1)=60 * 0.4
ElseIf Dtable. Rows (I). The Item (" B ")/B_average & lt; 4 Then
Arr1 (I, 1)=80 * 0.4
The Else
Arr1 (I, 1)=100 * 0.4
End the If
Next
Return arr1
End the Function
The End of the Class
The function of the implementation is the list of badp these four columns, respectively, to take a (maximum, minimum)/5 values, then the four columns of each row respectively divided by the value, the results back I'd like to deposit into the array

CodePudding user response:

Dim arr1 (,) As Int32 defines arr1 this array, it just did not assign size, cannot be directly behind the assignment, you are either with collection, finally converted to an array, or according to the number of lines to define size

CodePudding user response:

Such as defined by the
Dim arr1 (Dtable. Rows. The Count - 1, 1) As Int32
But why the data type is int32? You're not trying to take 0.4? That should be in decimal

CodePudding user response:

The
references to the tenth floor HZTLTGG response:
such as defined by the
Dim arr1 (Dtable. Rows. The Count - 1, 1) As Int32
But why the data type is int32? You're not trying to take 0.4? That should be use the decimal

I change the data type to double, Dim arr1 (4, 50) As a double
Then the Public Function SqlInput () As a Double (,) Function definition here
Now I want to call this function in the button, what should I write,
Dim Intoarr as new Intoarray
Return value=intoarr. Sqlinput (parameters)
What take the return value, call, parameters passed how to write,,,,
Great god help me to look at you, I was no parameters in this function,

CodePudding user response:

You didn't this parameter
Grammar can not write now return value type, the system will conclude that write their own can also

Dim Intoarr as new Intoarray
Dim the result as the as a Double (,)=intoarr. Sqlinput ()
  • Related