Array of public Structure Help me PLEASE!

kiwi

Member
Joined
Jul 12, 2006
Messages
14
Programming Experience
Beginner
Hy! I'm sorry if i can't explain my problem very well, i'm italian but i need help for a problem with vb.net program... so...

I made a web service that extract some value from a db and this result must be insered in this public structure:

VB.NET:
Public Structure SERVS1Result
Public NumeroComm As Integer
Public Comm As SComm
 
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
End Structure
and then I wrote:

Return SERVS1Result (the name of my public structure)

what is the problem?
the problem is that I have many result from my db and for this I need to create a Array of my Public Structure
I try to create it but i receive some messagge error!!

I post my code and i hope that you can help me, I try to ask help in many forum but nobody say me nothing PLEASE!!!

VB.NET:
<Start of function>
Public Com() As Object '<----------------------------------------///
 
[.....code....]
 
If Not risolvi = "" Then
objConn.Open()
 
 
Dim pc As String
Dim i As Integer = 0
Dim x As Integer = 0
Dim c As Integer
Dim objCmd2 As New OleDbCommand("Stringa di connessione", objConn)
Dim objReader2 As OleDbDataReader
objReader2 = objCmd2.ExecuteReader
 
While objReader2.Read
pc = (objReader2.GetString(9))
If pc = "Y" Then
i = i + 1
 
Com(i) = New SERVS1Result '<-----------------------------------///
 
Com(i).Comm.Nome = objReader2.GetString(2) 'Sede
Com(i).Comm.Indirizzo = objReader2.GetString(4) 'indirizzo
Com(i).Comm.telefono = objReader2.GetString(5) 'telefono
Com(i).Comm.Email = objReader2.GetString(8) 'email
Com(i).Comm.Cap = CapCom
Com(i).Comm.Comune = Comune
Com(i).Comm.SiglaProvincia = Provincia
 
 
End If
 
End While
 
objConn.Close()
objConn.Dispose()
 
Com(i).NumeroComm = i '<------------------------------------------///
 
 
For c = 0 To Com.Length '<-------------------------------///
Return Com(c) '<-----------------------------///
Next
 
 
End If
 
 
End Function
 
<End Function>
 
<Start Public Structure>
Public Structure SERVS1Result
Public NumeroComm As Integer
Public Comm As SComm
 
Public Structure SComm
Public Nome As String
Public Indirizzo As String
Public Cap As String
Public Comune As String
Public SiglaProvincia As String
Public Email As String
Public telefono As String
End Structure
End Structure

thank you
 
Last edited by a moderator:
Did you change SERVS1Result structure to class? If so, you create new instances of classes. For example:
VB.NET:
[SIZE=2]Com(0) = New SERVS1Result[/SIZE]
Also the structure and requirement is unclear. Why do you do this:
Com(0).Comm(1)
Com(0).Comm(2)
Com(0).Comm(3)
Com(0).Comm(4)
Com(0).Comm(5)
Com(0).Comm(6)
Com(0).Comm(7)
Com(0).Comm(8)
etc...

I thought the structure was:
Com(0).Comm(0)
Com(0).Comm(1)
Com(1).Comm(0)
Com(1).Comm(1)
Com(2).Comm(0)
Com(2).Comm(1)
Com(3).Comm(0)
Com(3).Comm(1)
etc...

If the first is correct then it is wrong for the 'Com' variable to reflect an array of SERVS1Result.
 
VB.NET:
Yes this is what them want, :
Com(0).Comm(0)
Com(0).Comm(1)
Com(1).Comm(0)
Com(1).Comm(1)
Com(2).Comm(0)
Com(2).Comm(1)
Com(3).Comm(0)
Com(3).Comm(1)

No I don't change my structure in a class

maybe i should do this?
VB.NET:
Dim Com as SERVS1Result

VB.NET:
[COLOR=#0000ff]ReDim[SIZE=2]Preserve[/SIZE][/COLOR][SIZE=2] Com.Comm(i) '<--------//
Com.Comm(i).Nome = objReader2.GetString(2) [/SIZE][SIZE=2][COLOR=#008000]'Sede
[/COLOR][/SIZE][SIZE=2]Com.Comm(i).Indirizzo = objReader2.GetString(4) [/SIZE][SIZE=2][COLOR=#008000]'indirizzo
[/COLOR][/SIZE][SIZE=2]Com.Comm(i).telefono = objReader2.GetString(5) [/SIZE][SIZE=2][COLOR=#008000]'telefono
[/COLOR][/SIZE][SIZE=2]Com.Comm(i).Email = objReader2.GetString(8) [/SIZE][SIZE=2][COLOR=#008000]'email
[/COLOR][/SIZE][SIZE=2]Com.Comm(i).Cap = CapCom
Com.Comm(i).Comune = Comune
Com.Comm(i).SiglaProvincia = Provincia
i = i + 1
[/SIZE]
but if i do so when i write Return Com give me a error:
Impossible to convert the value kind
SERVS1ResultClassAccess.SERVS1Result in matrix(?) a 1 dimension of
SERVS1ResultClassAccess.SERVS1Result


I must keep still com to start with him and close with him, but i must cicle comm to take all result (records) no?
 
Sorry, I haven't got a clue what you're talking about.
 
me too :(

Ok.... try with code, is incorrect the last code that i have insered...?

i must create a array of com too?
why (i don't think that this wrong i ask for curiosity) you wrote this?
Com(0).Comm(0)
Com(0).Comm(1)
Com(1).Comm(0)
Com(1).Comm(1)
Com(2).Comm(0)
Com(2).Comm(1)
Com(3).Comm(0)
Com(3).Comm(1)

I think should be so...
1 istance of SERVS1Result (com)
more istance (for each result) of Scomm (Comm)

then i wrote
Com.Comm(i) no?

Com don't must be call only one time?
VB.NET:
[COLOR=#0000ff]<[/COLOR][COLOR=#990000]ArrayOfSERVS1Result[/COLOR][COLOR=#ff0000] xmlns:xsi[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://www.w3.org/2001/XMLSchema-instance[/COLOR][/B][COLOR=#0000ff]" [/COLOR]
[COLOR=#ff0000] xmlns:xsd[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://www.w3.org/2001/XMLSchema[/COLOR][/B][COLOR=#0000ff]"[/COLOR]
[COLOR=#ff0000]x mlns[/COLOR][COLOR=#0000ff]="[/COLOR][B][COLOR=#ff0000]http://tempuri.org/[/COLOR][/B][COLOR=#0000ff]">[/COLOR]
[URL="http://localhost:2090/PsoapAccess/Service.asmx/SERVSUPP001#"][B][FONT=Courier New][COLOR=#ff0000]-[/COLOR][/FONT][/B][/URL] [COLOR=#0000ff]<[/COLOR][COLOR=#990000]SERVS1Result[/COLOR][COLOR=#0000ff]>[/COLOR]
 [COLOR=#0000ff]<[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR][B]3[/B][COLOR=#0000ff]</[/COLOR][COLOR=#990000]NumeroComm[/COLOR][COLOR=#0000ff]>[/COLOR]

and Comm for each result ?
VB.NET:
<SComm> 
            <Nome>[COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Nome>
            <Indirizzo>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Indirizzo>
            <Cap>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Cap>
            <Comune>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Comune>
            <SiglaProvincia>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</SiglaProvincia>
            <Email>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</Email>
            <telefono>[/COLOR][COLOR=#00008b][B]string[/B][/COLOR][COLOR=#000000]</telefono>
[COLOR=#000000]</SComm>[/COLOR][/COLOR]

try the last time to explain me PLEASE PLEASE...... PLEASE :confused:
 
I try so, i don't know why, but this is the only way that not give me many errors but one error!!


...this error:
Cast non valido dal tipo 'Object()' al tipo 'SComm()'
traslate:
invalid cast from type 'Object()' to SComm()


Please help me again!
VB.NET:
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] risolvi = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]objConn.Open()
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] prova [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SERVS1Result '<-----------//
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] Com = prova '<----------------//
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pc [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] x [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] c [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objCmd2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] OleDbCommand([/SIZE][SIZE=2][COLOR=#800000]"Connection String[/COLOR][/SIZE][SIZE=2][COLOR=#800000]'"[/COLOR][/SIZE][SIZE=2], objConn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objReader2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] OleDbDataReader
objReader2 = objCmd2.ExecuteReader
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] objReader2.Read
pec = (objReader2.GetString(9))
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] pc = [/SIZE][SIZE=2][COLOR=#800000]"Y"[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]ReDim[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Preserve[/COLOR][/SIZE][SIZE=2] Com.Comm(i) '<---------------//
Com.Comm(i).Nome = objReader2.GetString(2) [/SIZE][SIZE=2][COLOR=#008000]'Sede <--------------//
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).Indirizzo = objReader2.GetString(4) 'indirizzo
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).telefono = objReader2.GetString(5) 'telefono
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).Email = objReader2.GetString(8) 'email
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).Cap = CapCom
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).Comune = Comune
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'-Com.Comm(i).SiglaProvincia = Provincia
[/COLOR][/SIZE][SIZE=2]i = i + 1
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]objConn.Close()
objConn.Dispose()
[/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Return[/COLOR][/SIZE][SIZE=2] Com
[/SIZE][SIZE=2][/SIZE][COLOR=#0000ff][/COLOR][SIZE=2][COLOR=#008000]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Function
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE][SIZE=2] SERVS1Result'<-------------------//
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] NumeroComm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Comm() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SComm '<-----------------//
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Structure[/COLOR][/SIZE][SIZE=2] SComm
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Nome [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Indirizzo [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Cap [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Comune [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] SiglaProvincia [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] Email [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] telefono [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Structure
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Structure
[/COLOR][/SIZE]
 
Back
Top