473,739 Members | 6,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing an array, vb 2005 ee

New to this, I used to pass an array like this

function BytesToString(b yref myarray() as byte, somethingelse as long) as long

and
m = BytesToString(f ooBar(), bluenose)

This would send the descriptor or pointer to the array to the function

The acual code is
dim myarray() as byte = My.computer.fil esystem.ReadAll Bytes(infile)
res = BytesToString(m yarray(),1,4)) 'read first 4 bytes only

And the function is as above.

I get a "number of indices is less than the number of dimentions in the
indexed array"

I just do not understand this.. if I put the first element of the array in
there, I get other errors.

This file is one that I have to read Bytes and words from, so I need access
to each and every byte. ALso, the files can be over a gig, so I really do not
want readallbytes, as that can cause problems on some pc's this is to run on,
but fileget isn't working.. which I will post in another question.

(I realy want to use fileget, but that is in another question).

Jul 5 '07 #1
7 1735
berick <be****@discuss ions.microsoft. comwrote:
New to this, I used to pass an array like this

function BytesToString(b yref myarray() as byte, somethingelse as long) as long

and
m = BytesToString(f ooBar(), bluenose)

This would send the descriptor or pointer to the array to the function

The acual code is
dim myarray() as byte = My.computer.fil esystem.ReadAll Bytes(infile)
res = BytesToString(m yarray(),1,4)) 'read first 4 bytes only
I don't think that *is* your actual code:

1) You're passing in three parameters instead of two
2) You've got too many closing brackets

If you could post your real code, I'm sure we can work out what's going
on.

(I'm also somewhat perplexed by the name of your method, given that it
doesn't seem to have anything to do with strings.)

<snip>
This file is one that I have to read Bytes and words from, so I need access
to each and every byte. ALso, the files can be over a gig, so I really do not
want readallbytes, as that can cause problems on some pc's this is to run on,
but fileget isn't working.. which I will post in another question.

(I realy want to use fileget, but that is in another question).
Any reason for not using a FileStream, which is the idiomatic .NET way
of accessing data from a file?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 5 '07 #2
(not sure if this sould be in vs.dotnet.gener al or here .. my FileGet
question is over there)

Here is actual code:

Dim ress() As Byte = My.Computer.Fil eSystem.ReadAll Bytes(inFile)
res = BytesToString(r ess(), 1, 4)
Debug.Print(res )
Debug.Print(UBo und(ress).ToStr ing)

Private Function BytesToString(B yRef byteArray() As Byte, _
ByVal Start As ULong, ByVal numchars As Integer) As String

Dim s As String = ""
Dim i As ULong
For i = Start To numchars
s = s & Chr(byteArray(i - 1))

Next
Return s
End Function
Now, there is probably a built in routine to do this, but the help file is
not very robust
to spend much time there, and I tend to search Google or one of the three
books I have for answers, but passing an array I have not found in any manual
or search except on non-oop stuff, and I've been doing non-oop for years.

"Jon Skeet [C# MVP]" wrote:
berick <be****@discuss ions.microsoft. comwrote:
New to this, I used to pass an array like this

function BytesToString(b yref myarray() as byte, somethingelse as long) as long

and
m = BytesToString(f ooBar(), bluenose)

This would send the descriptor or pointer to the array to the function

The acual code is
dim myarray() as byte = My.computer.fil esystem.ReadAll Bytes(infile)
res = BytesToString(m yarray(),1,4)) 'read first 4 bytes only

I don't think that *is* your actual code:

1) You're passing in three parameters instead of two
2) You've got too many closing brackets

If you could post your real code, I'm sure we can work out what's going
on.

(I'm also somewhat perplexed by the name of your method, given that it
doesn't seem to have anything to do with strings.)

<snip>
This file is one that I have to read Bytes and words from, so I need access
to each and every byte. ALso, the files can be over a gig, so I really do not
want readallbytes, as that can cause problems on some pc's this is to run on,
but fileget isn't working.. which I will post in another question.

(I realy want to use fileget, but that is in another question).

Any reason for not using a FileStream, which is the idiomatic .NET way
of accessing data from a file?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 5 '07 #3
berick <be****@discuss ions.microsoft. comwrote:
(not sure if this sould be in vs.dotnet.gener al or here .. my FileGet
question is over there)

Here is actual code:

Dim ress() As Byte = My.Computer.Fil eSystem.ReadAll Bytes(inFile)
res = BytesToString(r ess(), 1, 4)
Debug.Print(res )
Debug.Print(UBo und(ress).ToStr ing)

Private Function BytesToString(B yRef byteArray() As Byte, _
ByVal Start As ULong, ByVal numchars As Integer) As String

Dim s As String = ""
Dim i As ULong
For i = Start To numchars
s = s & Chr(byteArray(i - 1))

Next
Return s
End Function
Right:
1) That's a nasty way to build up a string. Use Encoding.GetStr ing,
specifying the appropriate encoding.

2) The reason it wasn't compiling is that the name of the variable is
ress, not ress(). Just change this line:

res = BytesToString(r ess(), 1, 4)
to
res = BytesToString(r ess, 1, 4)

and it will compile. Encoding.GetStr ing replaces the method completely
though...
Now, there is probably a built in routine to do this, but the help file is
not very robust
to spend much time there, and I tend to search Google or one of the three
books I have for answers, but passing an array I have not found in any manual
or search except on non-oop stuff, and I've been doing non-oop for
years.
Arrays are already reference types. You don't have to pass them *by*
reference.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 5 '07 #4
I find that BinaryReader and FileStream.posi tion are doing the job very much
like get and seek did in the past. Very easy. ...

BUT... conversion is not as easy, so far... in the past, I could get a
string of chars from a file that represented a long, in 4 bytes and use CINT
to get the integer it represented. Now I get errors saying the string can't
be converted. I can take the ASC of each item and return the correct value,
but have not found how to get this directly..

The Hex code in the file is exactly this:
12 00 00 00
Where 12 00 is the lsb and 00 00 is the msb

I get this with
r = BinaryReader.re adChars(4)

but how do I get the integer? I've tried .readUINT16, and 32 and almost
everything and don't have it. I know it has to be simple, but here is another
item from years of non-oop programming causing a stumble. I can use asc(first
char) & asc(second) and so forth to get it but this can't be what I am
looking for as that can get very messy.

"Jon Skeet [C# MVP]" wrote:
berick <be****@discuss ions.microsoft. comwrote:
(not sure if this sould be in vs.dotnet.gener al or here .. my FileGet
question is over there)

Here is actual code:

Dim ress() As Byte = My.Computer.Fil eSystem.ReadAll Bytes(inFile)
res = BytesToString(r ess(), 1, 4)
Debug.Print(res )
Debug.Print(UBo und(ress).ToStr ing)

Private Function BytesToString(B yRef byteArray() As Byte, _
ByVal Start As ULong, ByVal numchars As Integer) As String

Dim s As String = ""
Dim i As ULong
For i = Start To numchars
s = s & Chr(byteArray(i - 1))

Next
Return s
End Function

Right:
1) That's a nasty way to build up a string. Use Encoding.GetStr ing,
specifying the appropriate encoding.

2) The reason it wasn't compiling is that the name of the variable is
ress, not ress(). Just change this line:

res = BytesToString(r ess(), 1, 4)
to
res = BytesToString(r ess, 1, 4)

and it will compile. Encoding.GetStr ing replaces the method completely
though...
Now, there is probably a built in routine to do this, but the help file is
not very robust
to spend much time there, and I tend to search Google or one of the three
books I have for answers, but passing an array I have not found in any manual
or search except on non-oop stuff, and I've been doing non-oop for
years.

Arrays are already reference types. You don't have to pass them *by*
reference.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 6 '07 #5
berick <be****@discuss ions.microsoft. comwrote:
I find that BinaryReader and FileStream.posi tion are doing the job very much
like get and seek did in the past. Very easy. ...

BUT... conversion is not as easy, so far... in the past, I could get a
string of chars from a file that represented a long
Hang on - are you sure you really mean a string of characters? What
*exactly* is the procedure which has been used to convert the data (and
when you say "long" what exactly do you mean?)
in 4 bytes and use CINT
to get the integer it represented. Now I get errors saying the string can't
be converted. I can take the ASC of each item and return the correct value,
but have not found how to get this directly..

The Hex code in the file is exactly this:
12 00 00 00
Where 12 00 is the lsb and 00 00 is the msb

I get this with
r = BinaryReader.re adChars(4)
Check *exactly* what ReadChars does - it's probably not exactly what
you're really expecting. Which encoding are you using?
but how do I get the integer? I've tried .readUINT16, and 32 and almost
everything and don't have it. I know it has to be simple, but here is another
item from years of non-oop programming causing a stumble. I can use asc(first
char) & asc(second) and so forth to get it but this can't be what I am
looking for as that can get very messy.
I'd avoid using ASC entirely, and use the Encoding class - that's the
surest way of converting between bytes and characters in an explicit
way.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 6 '07 #6
Ok, let me start from scratch. In the previous version, I stored things in a
string, but just needed something to get the following in:

The file is a pure binary with byte-by-byte info and headers which are 2, 4
or 8 bytes. I simply read those into the correct types with get(filenum,num
of bytes) after seeking the correct spot. Then, I get a chunk of data, that
I look at byte by byte and throw some away. Then the result gets put back
with a put statement. I stored all of these in a pure string. NO Unicode...
nothing. Just the plain byte-by-byte stuff. ANd I would repeate until this
ended. It is really raw bytes I need and not a string, but the string was a
convenient container for me to use.

I think maybe a dynamic byte array would work, but I have not used one and
am looking for examples to check out.

"Jon Skeet [C# MVP]" wrote:
berick <be****@discuss ions.microsoft. comwrote:
I find that BinaryReader and FileStream.posi tion are doing the job very much
like get and seek did in the past. Very easy. ...

BUT... conversion is not as easy, so far... in the past, I could get a
string of chars from a file that represented a long

Hang on - are you sure you really mean a string of characters? What
*exactly* is the procedure which has been used to convert the data (and
when you say "long" what exactly do you mean?)
in 4 bytes and use CINT
to get the integer it represented. Now I get errors saying the string can't
be converted. I can take the ASC of each item and return the correct value,
but have not found how to get this directly..

The Hex code in the file is exactly this:
12 00 00 00
Where 12 00 is the lsb and 00 00 is the msb

I get this with
r = BinaryReader.re adChars(4)

Check *exactly* what ReadChars does - it's probably not exactly what
you're really expecting. Which encoding are you using?
but how do I get the integer? I've tried .readUINT16, and 32 and almost
everything and don't have it. I know it has to be simple, but here is another
item from years of non-oop programming causing a stumble. I can use asc(first
char) & asc(second) and so forth to get it but this can't be what I am
looking for as that can get very messy.

I'd avoid using ASC entirely, and use the Encoding class - that's the
surest way of converting between bytes and characters in an explicit
way.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 6 '07 #7
berick <be****@discuss ions.microsoft. comwrote:
Ok, let me start from scratch. In the previous version, I stored things in a
string, but just needed something to get the following in:

The file is a pure binary with byte-by-byte info and headers which are 2, 4
or 8 bytes. I simply read those into the correct types with get(filenum,num
of bytes) after seeking the correct spot. Then, I get a chunk of data, that
I look at byte by byte and throw some away. Then the result gets put back
with a put statement. I stored all of these in a pure string. NO Unicode...
nothing. Just the plain byte-by-byte stuff. ANd I would repeate until this
ended. It is really raw bytes I need and not a string, but the string was a
convenient container for me to use.
Right - string is *not* a convenient way of doing this at all - string
is for text data. BinaryReader is the way forward - just call
ReadInt16, ReadInt32 or ReadInt64.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 7 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
6208
by: Oscar | last post by:
I am looking for a way to pass an ADO recordset that has been retrieved in an ASP page to another HTML-page. Is there someone who can provide me with a small sample or a link to see how this is done? regards, Oscar
58
10167
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
18
18634
by: laclac01 | last post by:
Is there a way to pass a 2d array to a function in c++ with out having to specifiy the number of elements in the array. Here is an example #include<iostream> using namespace std; int main() { int array;
8
4115
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
6
12659
by: DeepaK K C | last post by:
Could anybody tell me how to pass array to a function by value? -Deepak
11
4465
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
17
3597
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int (*fcmp)() = &cmp_fcn; qsort(..., fcmp); then everything works. But if instead I code qsort as:
0
1078
by: =?Utf-8?B?QmlsbHk=?= | last post by:
Hi, VS 2005/.NET 2.0 In my DAL i am running a query and passing the results into a local array. That array is being passed back to the BAL and through to the Presentaltion layer. Now, i would have though that there would be a problem accesssing the array in the presentation layer, but it appears to work. Is this functionality guarenteed or not? My understanding is that when the function is called in the DAL it creates the array in...
13
3205
by: Andy Baker | last post by:
I am attempting to write a .NET wrapper in C# for an SDK that has been supplied as a .LIB file and a .h header file. I have got most of the functions to work but am really struggling with the functions that require a structure to be passed to them. The function declaration in the .h file is of the form: SDCERR GetConfig(char *name, SDCConfig *cfg); where SDCConfig is a structure defined in the .h file. I am not much of a C (or C#)...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.