|
i have been given what seems like an imposible task of trying to read in an old random access file generated by VB6.. i have to parse out a ton of values out of this file, and to be honest i have no clue on if this is even possible..
here is what im doing currently:
FileStream aFile = new FileStream(m_strReportFilename, FileMode.Open);
byData = new byte[2];
aFile.Read(byData, 0, byData.Length);
int nInt = Convert.ToInt32(byData); this crashes on the last line with the error 'Specified cast is not valid '..
i have a listing of the structure of the file which consists of the following types: Integer , String (of set length), Currency (which is not a type in .NET), Boolean , and Date ..
i had it where i read in the whole file into a byte array to parse, but now im trying to just get the first integer out of the file.. can someone point me in the right direction please?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
hi,
i couldn't see any function call as you made. There is no any ToInt32 function accepting a byte array as a parameter. But i can suggest you a few way to do this.
But first you should correct the array length of byData to the value 4 ( for int values there needs a 4-byte space ).
Way 1 -
unsafe public static int AddressOf(byte[] variable)
{
int ptrptr;
fixed(byte* ptr = variable)
{ptrptr = (int) ptr;}
return ptrptr;
}
int byDataAddr = AddressOf( byData );
int * iValue = ( int * ) byDataAddr;
int nInt = *iValue;
Way 2 -
int nInt = ( ( int ) byData[3] ) << 24 + ( ( int ) byData[2] ) << 16 +
( ( int ) byData[1] ) << 8 + ( int ) byData[0];
there is a way more but not so important. those above may help you, i hope
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
thanks for the suggestion, i will try what you have suggested.. according to what ive been told an int in .net is 4 bytes, but in vb6 an int is 2 bytes, let me know if im mistaken.
thanks for the help, ill let you know how it goes!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
this has helped a bit with integers, but im having a hard time seeing how i would use either of these methods to read strings or bools, any suggestions?
thanks in advance!
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
way #1 - works, but is unsafe
way #2 - does not give correct values, i changed it to what is listed below since the Integers im reading are 2 bytes
int nInt = ( ( int ) byData[1] ) << 8 + ( int ) byData[0]; any suggestions on how to get the correct value without being 'unsafe', and how to parse other types such as strings, dates, and booleans?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
dazinith wrote:
without being 'unsafe'
unsafe only if used incorrectly. What u have works, thus is cant be unsafe in a danger sense.
dazinith wrote:
how to parse other types such as strings, dates, and booleans?
Have a look at the Encoder classes as well as the Convert class.
A good knowledge of how types are allocated in VB would also help in your case.
<a TITLE="See my user info" href=http:
|
|
|
|
|
way - 1 : it may be unsafe. but unsafe doesn't mean that it is really unsafe . it means that "be carefulu on using unsafe, if you incorrectly use it you may crash the system LOL ). bu if you want your code pure Managed then you are wright.
way - 2 : When you wrote an int value to a file or a memory it is written as fallows,
first low part of the value and then the high part.
2 bytes value (byte0-byte1) byte1 and then byte2
4 bytes value (byte0-byte1-byte2-byte3) byte3 and then byte2 and then byte1 and latest byte0
So you must know the layout of the value of the byte array you try to read from a file. so lıater you can write the function below to read different types of value from a byte array
public static bool GetBool( byte [] MyData , int index )
{
return ( MyData[ index ] == 0 ? false : true );
}
public static short GetShort( byte [] MyData , int index )
{
short s = 0;
s = (short) ( ( ( int ) MyData[ index + 1 ] ) << 8 );
s += (short ) Mydata[ index ];
return s;
}
public static int GetInt( byte [] MyData , int index )
{
int s = 0;
s = ( ( int ) MyData[ index + 3 ] ) << 24;
s = ( ( int ) MyData[ index + 2 ] ) << 16;
s = ( ( int ) MyData[ index + 1 ] ) << 8;
s += ( int ) Mydata[ index ];
return s;
}
public static string GetString( byte [] MyData , int index , int len )
{
string s;
s = Encoding.ASCII.GetString( MyData , index , len );
return s;
}
Before converting date values from a byte array, you must know what format it has. Because i don't know the format, so i cann't help you
cheers,
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Trying doing something like:
FileStream aFile = new FileStream(m_strReportFilename, FileMode.Open);
BinaryReader br = new BinaryReader(aFile);
Int16 nInt = br.ReadInt16();
This reads in 2 bytes from the FileStream and then converts them to a 16-bit integer (short in c# and c++). I used Int16 just to show the actual size of the return integer. Look at all the members of BinaryReader for more information.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Hi,
I need to have a combo box with a lot of elements ( like 200, or maybe 400 elements), what I wnat to do is that the user type the name and it goes showing the most similar matches ( something like VStudio net makes, but no need for strange control just in a combo it's ok).
Is there someway to do that ? or Should I implement a new control ?, Greetings
Braulio
|
|
|
|
|
the combobox when set to a droplist (cannot type in it) will automatically go to an item which begins with the character the user presses.. example: you press 'h', and it moves to the first item begining with 'h', hit 'h' again and it goes to the next one, etc..
as for the functionality you are looking for i have not seen anything like that.. your best bet would be adding a message handler for when a key is pressed in the combobox, and doing a BeginsWith() search with what they have typed in, if you find something then set the combobox selection to that item.. the problem is keeping the submenu expanded while they are typing.. i have no clue on the actual implementation, but im pretty sure its not built in..
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Hi,
I've found some interesting code snippet for that autocomplete, but I think it doesn't show the list meanwhile you are typing
I found this code somewhere.
[code]
Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.Text = ""
Me.ComboBox1.Items.Add("a")
Me.ComboBox1.Items.Add("aaa")
Me.ComboBox1.Items.Add("combo")
Me.ComboBox1.Items.Add("combobox")
Me.ComboBox1.Items.Add("combobox test")
Me.ComboBox1.Items.Add("common")
Me.ComboBox1.Items.Add("common dialog")
End Sub
Private Sub ComboBox1_KeyUp(ByVal sender As Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles
ComboBox1.KeyUp
Dim index As Integer
Dim actual As String
Dim found As String
' Do nothing for some keys such as navigation keys.
If ((e.KeyCode = Keys.Back) Or _
(e.KeyCode = Keys.Left) Or _
(e.KeyCode = Keys.Right) Or _
(e.KeyCode = Keys.Up) Or _
(e.KeyCode = Keys.Delete) Or _
(e.KeyCode = Keys.Down) Or _
(e.KeyCode = Keys.PageUp) Or _
(e.KeyCode = Keys.PageDown) Or _
(e.KeyCode = Keys.Home) Or _
(e.KeyCode = Keys.End)) Then
Return
End If
' Store the actual text that has been typed.
actual = Me.ComboBox1.Text
' Find the first match for the typed value.s
index = Me.ComboBox1.FindString(actual)
' Get the text of the first match.
If (index > -1) Then
found = Me.ComboBox1.Items(index).ToString()
' Select this item from the list.
Me.ComboBox1.SelectedIndex = index
' Select the portion of the text that was
automatically
' added so that additional typing will replace
it.
Me.ComboBox1.SelectionStart = actual.Length
Me.ComboBox1.SelectionLength = found.Length
End If
End Sub
[/code]
|
|
|
|
|
There is something with Internet explorer 5.5, there is a DLL, that has that kind of control ( that cool combos stuff comboboxEx), now I have to study, how to use it in C#...
|
|
|
|
|
|
if you add a new class entity and then assign an object to it in the constructor.
public class MyClass
{
private SolidBrush sb;
public MyClass(Color brushcolor)
{
this.sb = new SolidBrush(brushcolor);
}
This will set the brush colours during instantiation.
"I have a strange ginger man living on my roof!"
"...does PHP need templates? I don't think so because PHP's data is loosely typed. It couldn't care less if the data was about strings or potato fritters." -John Lim
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
AFAIK it is the only way you can create a brush object at instantiation that can be accessible to OnPaint.
"I have a strange ginger man living on my roof!"
"...does PHP need templates? I don't think so because PHP's data is loosely typed. It couldn't care less if the data was about strings or potato fritters." -John Lim
Jonathan 'nonny' Newman
Homepage [www.nonny.com] [^]
|
|
|
|
|
As I'm about to do in my project, I think it's better to make pens and brushes member variables -- or in my case, static variables because the same brush can be used across all instantiations -- so you don't have to constantly construct and dispose brushes in the OnPaint method.
|
|
|
|
|
You can, but make sure you call dispose on them at the end of the method, else it with quick swallow all your RAM.
<a TITLE="See my user info" href=http:
|
|
|
|
|
Hi leppie,
I have a question about that that I simply can't find a simple answer to in the MSDN documentation.
If I create a pen, brush, etc., in the OnPaint event, do I need to manually displose of it before exiting the OnPaint event?
Thanks!
Marc
Help! I'm an AI running around in someone's f*cked up universe simulator. Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus Every line of code is a liability - Taka Muraoka Microsoft deliberately adds arbitrary layers of complexity to make it difficult to deliver Windows features on non-Windows platforms--Microsoft's "Halloween files"
|
|
|
|
|
Marc Clifton wrote:
If I create a pen, brush, etc., in the OnPaint event, do I need to manually displose of it before exiting the OnPaint event?
Preferably! The GC will dispose them eventually. Have a look in task manager to see if extra handles are continuously created.
<a TITLE="See my user info" href=http:
|
|
|
|
|
Nice to meet you !
I have simple question ...
I have experience for develop SNMP Manager in UNIX system using by C,tcl...
in that case, using UCD-SNMP ...
Now I do want develop SNMP Manager in WindowsXP using by C#.
(Microsoft Visual Studio .NET)
in this case , what can i do ?
is it support snmplib or any kinds of extension in C# ?
==============================
Name : B.S. Yoon
mail to : bsyoon@mercurykr.com
==============================
|
|
|
|
|
hi,
i have already written a class using the wsnmp32.dll api. if you want to have it , please e-mail me..
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Thanks your kindly answer !!
If it is possible , Can you send to me wsnmp32.dll api and
can you let me know more than detail for using wsnmp32.dll !
This is first time for develop windows programing...
i hope your kindly support !!
my email address : bsyoon@mercurykr.com
==============================
Name : B.S. Yoon
mail to : bsyoon@mercurykr.com
==============================
|
|
|
|
|
check your e-mail box , please
Doing something is better than doing nothing. So ... Move !
|
|
|
|
|
Thanks your kindly answer !!
also, I get your snmp project file..
when i degug your project file, your source is needed DB (mdb)
"D:\MyPrograms\VbNet\C\OidTables\OidTable.mdb;"
38 line in "ClsOidTable.cs"
but i don't have and Don't know that Configuration for "OidTable.mdb"
can i receive OidTable.mdb file?
==============================
Name : B.S. Yoon
mail to : bsyoon@mercurykr.com
==============================
|
|
|
|
|
Sure...
Check your e-mail box , please. i've already sent it
Doing something is better than doing nothing. So ... Move !
|
|
|
|