|
Whenever calculating time I like to see it as a time span and not a date, I find it cleaner logically and its a safer when negative values might be present (they always come when you least expect it). When using a TimeSpan you convert twice and test for negative values once...
Natza Mitzi
|
|
|
|
|
when i tried using a few api functions like FindWindow
they didn't work for me
no error was produced in the debug mode(ie i ran using F5)
how is that??
is there a new way to use api in vb 2008
cause in older vb it is working??
TheMrProgrammer
|
|
|
|
|
Ya, using api in .net is different from VB 6.0. In VB 6.0 we often uses api call but in .net. Here is an example,
<DllImport("KERNEL32.DLL", EntryPoint:="GetSystemDirectoryW", _
SetLastError:=True, CharSet:=CharSet.Unicode, _
ExactSpelling:=True, _
CallingConvention:=CallingConvention.StdCall)> _
Public Function GetSystemDirectory(ByVal Buffer _
As StringBuilder, ByVal Size As Integer) As Long
' Leave function empty - DLLImport attribute
' forces calls to GetSystemDirectory to
' be forwarded to GetSystemDirectory in KERNEL32.DLL
End Function
Please use google for futher clarification.
|
|
|
|
|
The process is known as PInvoke or P/Invoke.
If you search MSDN, or Google on those terms you will get lots of examples.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
The program I am writing now needs to send data through the serial port automatically. So far, I have been able to put it into a queue list and send it out using a timer. The problem is, the data sent is in two parts and must come consecutively after each part. After that, the timer kicks in and send another two part data.
Does anyone have any ideas on how to do it?
|
|
|
|
|
Your description isn't very clear. How to do what?? Send the data? It sounds like you already have that part down. Use a Timer? Look into System.Threading.Timer[^].
|
|
|
|
|
Hmmmm, the main idea is to queue a list of test to send through the serialport. I have got it down with a timer and queue list. The problem is the test themselves. Each test has a function that calls the device connected to the serial port. However, the functions itself is in two parts. I need to send it one after the other.
For example, (Test 1,2,3,etc) -> queue them -> send through serialport.
But each test, e.g Test 1 - function "a" and function "b" needs to be sent consecutively.
Anyh ideas on how to work around it? I tried putting it into an array and sending it out as an array but the device can't process the information fast enough. I need at least a 2sec delay.
|
|
|
|
|
I don't know how you designed the code, the quick'n'dirty method to pacing something like this at a 2 second interval would be Thread.Sleep(2000).
Normally, I'd probably build a component that handles it's own queue and keeps not only the message that should be sent, but with it, a delay time for how long until the item should be sent. Pop the item off the queue, check it's delay time and setup a Threading.Timer with the delay value and return. The Timer callback will call your code that sends the data to the device.
|
|
|
|
|
That sounds like a good idea. I'll give it a go and see if it works with it. Thanks a lot
|
|
|
|
|
Right, tested this out but I have a problem of with the string "DataSend". Every time it checks for the the varible that I want, it just repeats itself. For example, I queued the test according to "c", "a", and then "c" again. So the queue sends out "c", "a",and lastly "c". The first time it runs, works perfectly. When the timer tick even kicks in, and sends out the next variable "a", I checked it for "a" and it goes well. After that, I checked for the third variable "c", it skips that and goes straight to "a" instead. What happened here? I don't really understand why it refuses to move forward.
Timer1 tick event
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If tasklist.Count > 0 Then
'Run the next test
DataSend = tasklist.Dequeue()
ListBox1.Items.RemoveAt(0)
serialPort.Write(DataSend)
If DataSend.Contains("c") = True Then
Timer2.Enabled = True
Timer1.Enabled = False
ElseIf DataSend.Contains("b") = True Then
serialPort.Write(DataSend)
Timer1.Enabled = True
Timer2.Enabled = False
ElseIf DataSend.Contains("a") = True Then
serialPort.Write(DataSend)
Timer1.Enabled = True
Timer2.Enabled = False
End If
Else
serialPort.Close()
PortStatus.Text = serialPort.PortName & " disconnected."
Disconnect.Enabled = False
Connect.Enabled = True
Timer1.Enabled = False
Timer2.Enabled = False
MsgBox("Finished All Test")
End If
End Sub
Timer 2 tick event, just an event to extend the time for variable "c"
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
serialPort.Write("p" & vbCrLf)
Timer2.Enabled = False
Timer1.Enabled = True
End Sub
I tried making the string empty before dequeue but it doesn't work. Any ideas on how to work around this?
|
|
|
|
|
This might be a possible bug in vs2005 (I know there is a 2008 but have to use 2005 for this one), I did do a search in google but couldn't find an explanation.
I have a usercontrol that's very simple, it just holds a state (and adjusts its text value).
When I place this usercontrol on a form, from time to time I get build errors.
It's easy to fix but very annoying.
Fix = go into designer off the form and delete the project namespace
so: the control is declared like: projectname.usercontrolname
when I delete the projectname. it builds fine and works fine.
Anyone know if this is a bug or how I can fix this, it's really getting on my nervs.
Thanks in advance
|
|
|
|
|
For what it is worth, I have had a similar problem in VS 2003 with datasets.
I would get a build error, and then I would find that the studio had "very helpfully" corrected the generated code.
I would "decorrect" it, and it would work fine, until the next time I built the project.
Finally I just started an entirely new solution / project, recreated all controls, etc, and copied all my own code. No problems after that.
I guess it depends on how badly it gets on your nerves, if it is worth the trouble.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan Hakkesteegt wrote: Finally I just started an entirely new solution / project, recreated all controls, etc, and copied all my own code. No problems after that.
Tried that to but didn't help me
I did find that it only happens when I have the form open in design mode, so my fix at the moment is making sure I don't have any of the forms open in design mode when building
|
|
|
|
|
I must say that VS 2005 never liked me, so I switched back to 2003 and made due until VS 2008 came out.
Which brings to mind, if you need to use 2005 because the app is in .net 2.0, I think you can use VS 2008 and just not convert the project to .net 3.5
My advice is free, and you may get what you paid for.
|
|
|
|
|
Johan Hakkesteegt wrote: Which brings to mind, if you need to use 2005 because the app is in .net 2.0, I think you can use VS 2008 and just not convert the project to .net 3.5
I know there is an option in 2008 that lets you specify the framework you want to use (when creating a new project its on the right upper corner I think).
But the framework is not why I can't use 2008, this project is an add-on for another program, the creators of that program created a sdk + some wizards and those wizards only work in 2005 (there working on a 2008 version but there very slow )
I don't use the wizards much but when starting out on something like this they can be handy from time to time.
|
|
|
|
|
Hi
I'm trying to script a scheduled task, and I'm using WMI do do this, but I'm not able to define the name for the new, scheduled task I'm scripting. I only get a generic name such as AT1 or AT2.
My script is as follows:
strComputer = InputBox("Machine you're genrating shedule on",_
"Scheduled task configurator")
if strComputer="" then
wscript.quit
end if
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
JobID = "PendingInfoCheck"
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create _
("C:\script.vbs", "********030000.000000-420", _
True , 1 OR 2 OR 4 OR 8 OR 16 OR 32 OR 64, , , JobID)
Wscript.Echo errJobCreated
I've tried to set the JobID, and it worked once, but nothing after the first time.
Please Help
TheScripter
|
|
|
|
|
There's no way to do it with WMI. All of the fields that would describe a "normal" job using the Task Schedular UI are not the same as WMI created jobs. You can modify a WMI created job, but once done, you can no longer use WMI to alter the job. There is no way to properly name a job using WMI.
|
|
|
|
|
Hi, I only have VB6 and need to write a program to parse mpeg4-asp frames (each frame is a "bitstream" ie a stream of sequential bits flowing across byte/word/longword boundaries).
Unfortunately VB6 has no unsigned data types, nor native bit operations, making masking and shifting left/right very difficult as you have to write your own functions to take into account (test for and fudge) the sign bit (eg bit 31 of the bit range 31..0 for long). Since any given file could have cumulative bitstreams of 4Gb, imaging how much life gets sucked out of the PC when using a per-bit home-grown function call with all the right masking and signbit testing/fixing complexity...
Does anyone know of system calls (eg kernel32) or some such which makes bitstream operations easy (eg rotate/shift longword/word/byte left and right, integer value of an arbitrarily positioned set of bits, etc) ?
Assume XP-SP3, and latest Java runtime if that helps, but no .NET since an objective is to be able to run on .NET-free PCs.
|
|
|
|
|
Don't be an idiot - get VB.Net or C# express and use it. IT COSTS NOTHING and you will get a lot more support from the forums.
VB6 is dead and no longer supported, do not waste your time starting with VB6
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks, however did you actually read the post which stated an objective "but no .NET since an objective is to be able to run on .NET-free PCs" ? My only other choice is free Java with the netbeans IDE and I already have a VB6 framework in place...
You see how complex it can get just with just a couple of operations, from the code:
Option Explicit
Option Base 0
Option Compare Binary
Sub Main()
' Define and create an object for bitstream operations
Dim BitStream As BitStreamVB6
Set BitStream = New BitStreamVB6
MsgBox "just created a new BitStreamVB6 object by Set variable BitStream "
Dim b(0 To 3) As Byte
Dim s As String
Dim i32 As Long
Dim i16 As Integer
Dim i As Long
Dim j As Long
Dim k As Long
Dim l As Long
Dim z As Long
Dim lw As Long
Dim stmp As String
lw = &H80000000 ' 2^31 is the sign bit ?
s = ""
For z = 0 To 32
s = s & " right(&H" & Hex(lw) & "," & z & ")=&H" & Hex(BitStream.i32_ShiftRight(lw, z)) & vbCrLf
Next z
MsgBox s
lw = &H1& ' 2^31 is the sign bit ?
s = ""
For z = 0 To 32
s = s & " left(&H" & Hex(lw) & "," & z & ")=&H" & Hex(BitStream.i32_ShiftLeft(lw, z)) & vbCrLf
Next z
MsgBox s
End Sub
and the object BitStreamVB6
Option Explicit
Option Base 0
Option Compare Binary
' LITTLE-ENDIAN (x86 architecture) considerations :
' http:
' text values D C B A
' Bytes 3 2 1 0
' Integer Maths - Most significant bit 31 0 Least Significant Bit
' Appearance of string when printed (backward to storage as appears above)= A B C D
'
'ie bits {31 30 29 28 27 26 25 24} | {23 22 21 20 19 18 17 16} | {15 14 13 12 11 10 09 08} | {07 06 05 04 03 02 01 00}
' text values ---------- D ---------- ---------- C ---------- ---------- B ---------- ---------- A ----------
' byte number 3 2 1 0
'
' However the sign bit causes OVERFLOW PROBLEMS in VB6 when masking and checking,
' so you have to check for it specifically and treat it separately
' eg the sign bit for LONG it is bit 31 - base zero
' for INTEGER it is bit 15 - base zero
' for BYTE it is bit 07 - base zero
'---------------------------------------------------------------------------------------------------
'
'byte little-endian sequential bytes in the byte
' 0 07 06 05 04 03 02 01 00
' 1 15 14 13 12 11 10 09 08
' 2 23 22 21 20 19 18 17 16
' 3 31 30 29 28 27 26 25 24
'
' When bytes read from a file, they are byte 0,1,2,3,4,5,6...
'
' So, for an mpeg4 bitstream read from a file byte by byte,
' IS the starting bit at the LEFT or the RIGHT of each byte ?
' Need to check the C code of mpeg4modifier for the answer...
'
'---------------------------------------------------------------------------------------------------
'
' Little-endian based bit masks.
'
' To check a bit is set are return a boolean True or False, use
' IsSet = (i32 AND i32_bit_31) = i32_bit_31 ' however in VB6 this returns a 16 byte integer FFFF=true 0000=false
' To check a bit is set are return a single bit in little-endian bit 0 (see above)
' BitValue = IIf(((i32 And i32_bit_31) = i32_bit_31), i32_bit_00, 0)
'
Const i32_bit_00 As Long = &H1&
Const i32_bit_01 As Long = &H2&
Const i32_bit_02 As Long = &H4&
Const i32_bit_03 As Long = &H8&
Const i32_bit_04 As Long = &H10&
Const i32_bit_05 As Long = &H20&
Const i32_bit_06 As Long = &H40&
Const i32_bit_07 As Long = &H80&
Const i32_bit_08 As Long = &H100&
Const i32_bit_09 As Long = &H200&
Const i32_bit_10 As Long = &H400&
Const i32_bit_11 As Long = &H800&
Const i32_bit_12 As Long = &H1000&
Const i32_bit_13 As Long = &H2000&
Const i32_bit_14 As Long = &H4000&
Const i32_bit_15 As Long = &H8000&
Const i32_bit_16 As Long = &H10000
Const i32_bit_17 As Long = &H20000
Const i32_bit_18 As Long = &H40000
Const i32_bit_19 As Long = &H80000
Const i32_bit_20 As Long = &H100000
Const i32_bit_21 As Long = &H200000
Const i32_bit_22 As Long = &H400000
Const i32_bit_23 As Long = &H800000
Const i32_bit_24 As Long = &H1000000
Const i32_bit_25 As Long = &H2000000
Const i32_bit_26 As Long = &H4000000
Const i32_bit_27 As Long = &H8000000
Const i32_bit_28 As Long = &H10000000
Const i32_bit_29 As Long = &H20000000
Const i32_bit_30 As Long = &H40000000
Const i32_bit_31 As Long = &H80000000
Const i16_bit_00 As Integer = &H1
Const i16_bit_01 As Integer = &H2
Const i16_bit_02 As Integer = &H4
Const i16_bit_03 As Integer = &H8
Const i16_bit_04 As Integer = &H10
Const i16_bit_05 As Integer = &H20
Const i16_bit_06 As Integer = &H40
Const i16_bit_07 As Integer = &H80
Const i16_bit_08 As Integer = &H100
Const i16_bit_09 As Integer = &H200
Const i16_bit_10 As Integer = &H400
Const i16_bit_11 As Integer = &H800
Const i16_bit_12 As Integer = &H1000
Const i16_bit_13 As Integer = &H2000
Const i16_bit_14 As Integer = &H4000
Const i16_bit_15 As Integer = &H8000
Const i08_bit_00 As Byte = &H1
Const i08_bit_01 As Byte = &H2
Const i08_bit_02 As Byte = &H4
Const i08_bit_03 As Byte = &H8
Const i08_bit_04 As Byte = &H10
Const i08_bit_05 As Byte = &H20
Const i08_bit_06 As Byte = &H40
Const i08_bit_07 As Byte = &H80
Const i32_mask_byte0 As Long = &HFF& ' *** CAREFUL HERE - if you leave the trailing "&" off then it all falls to pieces !!!!!!!!!!!!!!!!
Const i32_mask_byte1 As Long = &HFF00& ' *** CAREFUL HERE - if you leave the trailing "&" off then it all falls to pieces !!!!!!!!!!!!!!!!
Const i32_mask_byte2 As Long = &HFF0000
Const i32_mask_byte3_nosignbit As Long = &H7F000000 ' notice this excludes the sign bit at bit07 (bit31 if the long)
Const i16_mask_byte0 As Long = &HFF
Const i16_mask_byte1_nosignbit As Long = &H7F00 ' notice this excludes the sign bit at bit07 (bit15 if the int)
Const i08_mask_byte0_nosignbit As Long = &H7F ' notice this excludes the sign bit at bit07 (bit07 of the byte)
Private i32_bitarray(0 To 31) As Long
Private i16_bitarray(0 To 15) As Integer
Private i08_bitarray(0 To 7) As Byte
Private tmp_long As Long
Private signbit_long As Long
Private tmp_int As Integer
Private signbit_int As Integer
Private tmp_byte As Byte
Private signbit_byte As Byte
Private Sub Class_Initialize()
' Initialise bitarrays ready for use in masking by (zero-based) "bit number"
' MsgBox " in Class_Initialize in BitStreamVB6"
i32_bitarray(0) = i32_bit_00
i32_bitarray(1) = i32_bit_01
i32_bitarray(2) = i32_bit_02
i32_bitarray(3) = i32_bit_03
i32_bitarray(4) = i32_bit_04
i32_bitarray(5) = i32_bit_05
i32_bitarray(6) = i32_bit_06
i32_bitarray(7) = i32_bit_07
i32_bitarray(8) = i32_bit_08
i32_bitarray(9) = i32_bit_09
i32_bitarray(10) = i32_bit_10
i32_bitarray(11) = i32_bit_11
i32_bitarray(12) = i32_bit_12
i32_bitarray(13) = i32_bit_13
i32_bitarray(14) = i32_bit_14
i32_bitarray(15) = i32_bit_15
i32_bitarray(16) = i32_bit_16
i32_bitarray(17) = i32_bit_17
i32_bitarray(18) = i32_bit_18
i32_bitarray(19) = i32_bit_19
i32_bitarray(20) = i32_bit_20
i32_bitarray(21) = i32_bit_21
i32_bitarray(22) = i32_bit_22
i32_bitarray(23) = i32_bit_23
i32_bitarray(24) = i32_bit_24
i32_bitarray(25) = i32_bit_25
i32_bitarray(26) = i32_bit_26
i32_bitarray(27) = i32_bit_27
i32_bitarray(28) = i32_bit_28
i32_bitarray(29) = i32_bit_29
i32_bitarray(30) = i32_bit_30
i32_bitarray(31) = i32_bit_31
i16_bitarray(0) = i16_bit_00
i16_bitarray(1) = i16_bit_01
i16_bitarray(2) = i16_bit_02
i16_bitarray(3) = i16_bit_03
i16_bitarray(4) = i16_bit_04
i16_bitarray(5) = i16_bit_05
i16_bitarray(6) = i16_bit_06
i16_bitarray(7) = i16_bit_07
i16_bitarray(8) = i16_bit_08
i16_bitarray(9) = i16_bit_09
i16_bitarray(10) = i16_bit_10
i16_bitarray(11) = i16_bit_11
i16_bitarray(12) = i16_bit_12
i16_bitarray(13) = i16_bit_13
i16_bitarray(14) = i16_bit_14
i16_bitarray(15) = i16_bit_15
i08_bitarray(0) = i08_bit_00
i08_bitarray(1) = i08_bit_01
i08_bitarray(2) = i08_bit_02
i08_bitarray(3) = i08_bit_03
i08_bitarray(4) = i08_bit_04
i08_bitarray(5) = i08_bit_05
i08_bitarray(6) = i08_bit_06
i08_bitarray(7) = i08_bit_07
'MsgBox "Class_Initialize: i32 masks[0..3]=" & Hex(i32_mask_byte0) & " " & Hex(i32_mask_byte1) & " " & Hex(i32_mask_byte2) & " " & Hex(i32_mask_byte3_nosignbit)
End Sub
Private Sub Class_Terminate()
' MsgBox " in Class_Terminate in BitStreamVB6"
End Sub
Sub i32_to_bytearray(ByRef src_i32 As Long, ByRef dst_i8() As Byte)
' Copy up to 4 bytes from an i32 into a byte array
dst_i8(0) = (src_i32 And i32_mask_byte0)
dst_i8(1) = (src_i32 And i32_mask_byte1) \ i32_bit_08
dst_i8(2) = (src_i32 And i32_mask_byte2) \ i32_bit_16
dst_i8(3) = (src_i32 And i32_mask_byte3_nosignbit) \ i32_bit_24 ' notice it is masked by 7F and not FF due to the sign bit issue
If (src_i32 And i32_bit_31) = i32_bit_31 Then ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
dst_i8(3) = dst_i8(3) Or i08_bit_07
End If
End Sub
Sub i32_to_string(ByRef src_i32 As Long, ByRef dst_ch As String)
' Copy 4 bytes from an i32 into a string
Dim stringToReturn As String
Dim ch1 As String * 1
Dim longwordUpperByte As Long
dst_ch = ""
ch1 = Chr(src_i32 And i32_mask_byte0)
dst_ch = dst_ch & ch1
ch1 = Chr((src_i32 And i32_mask_byte1) \ i32_bit_08)
dst_ch = dst_ch & ch1
ch1 = Chr((src_i32 And i32_mask_byte2) \ i32_bit_16)
dst_ch = dst_ch & ch1
longwordUpperByte = (src_i32 And i32_mask_byte3_nosignbit) \ i32_bit_24 ' notice it is masked by 7F and not FF due to the sign bit issue
If (src_i32 And i32_bit_31) = i32_bit_31 Then ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
longwordUpperByte = longwordUpperByte Or i32_bit_07
End If
ch1 = Chr(longwordUpperByte)
dst_ch = dst_ch & ch1
End Sub
Sub i16_to_bytearray(ByRef src_i16 As Integer, ByRef dst_i8() As Byte)
' Copy 2 bytes from an i16 into a byte array
dst_i8(0) = (src_i16 And i16_mask_byte0)
dst_i8(1) = (src_i16 And i16_mask_byte1_nosignbit) \ i16_bit_08 ' notice it is masked by 7F and not FF due to the sign bit issue
If (src_i16 And i16_bit_15) = i16_bit_15 Then ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
dst_i8(1) = dst_i8(1) Or i08_bit_07
End If
End Sub
Sub i16_to_string(ByRef src_i16 As Integer, ByRef dst_ch As String)
' Copy 4 bytes from an i32 into a string
Dim ch1 As String * 1
Dim wordUpperByte As Integer
dst_ch = ""
ch1 = Chr(src_i16 And i16_mask_byte0)
dst_ch = dst_ch & ch1
wordUpperByte = (src_i16 And i16_mask_byte1_nosignbit) \ i16_bit_08 ' notice it is masked by 7F and not FF due to the sign bit issue
If (src_i16 And i16_bit_15) = i16_bit_15 Then ' sign bit was set, ensure bit 7 (base 0) is also set in the retrieved byte too
wordUpperByte = wordUpperByte Or i16_bit_07
End If
ch1 = Chr(wordUpperByte)
dst_ch = dst_ch & ch1
End Sub
Function i32_GetBit(ByRef src_i32 As Long, ByVal src_bitno As Long) As Long
If src_bitno < 0 Or src_bitno > 31 Then
Err.Raise 5, "i32_is_bit_set", "bit number not in range [0..31)"
End If
i32_GetBit = IIf(((src_i32 And i32_bitarray(src_bitno)) = i32_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function
Function i16_GetBit(ByRef src_i16 As Integer, ByVal src_bitno As Long) As Long
If src_bitno < 0 Or src_bitno > 15 Then
Err.Raise 5, "i16_is_bit_set", "bit number not in range [0..15)"
End If
i16_GetBit = IIf(((src_i16 And i16_bitarray(src_bitno)) = i16_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function
Function i08_GetBit(ByRef src_i08 As Byte, ByVal src_bitno As Long) As Long
If src_bitno < 0 Or src_bitno > 7 Then
Err.Raise 5, "i08_is_bit_set", "bit number not in range [0..7)"
End If
i08_GetBit = IIf(((src_i08 And i08_bitarray(src_bitno)) = i08_bitarray(src_bitno)), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
End Function
Function i32_ShiftRight(ByRef src_i32 As Long, ByVal src_nobits As Long) As Long
If src_nobits < 0 Or src_nobits > 32 Then
Err.Raise 5, "i32_ShiftRight", "bit number not in range [0..32)"
End If
If src_nobits = 0 Then ' no shifting, zero bitshift requested :)
i32_ShiftRight = src_i32
Exit Function
End If
If src_nobits = 32 Then ' full longword bitshift requested, hence will be zero :)
i32_ShiftRight = &H0&
Exit Function
End If
' the damn sign bit stuffs things up
signbit_long = src_i32 And i32_bit_31 ' save the sign bit, we need to move it separately
If src_nobits = 31 Then ' sign bit requested via a shiftright by 31 bits, so handle the special case because VB6 overflows if you don't
i32_ShiftRight = IIf((signbit_long = i32_bit_31), 1, 0) ' RETURN - IF 1 BIR CLEAR OR 1 IF BIT SET
Exit Function
End If
tmp_long = src_i32 And (Not i32_bit_31) ' make a variable excluding the sign bit
tmp_long = tmp_long / (2 ^ src_nobits) ' shift bits right by simple division
'now put back the sign bit also shifted right by src_nobits bits
If signbit_long = i32_bit_31 Then
signbit_long = i32_bitarray(31 - src_nobits) ' use a lookup to do it instead of division because VB6 hates signs
Else
signbit_long = &H0&
End If
i32_ShiftRight = tmp_long Or signbit_long
End Function
Function i32_ShiftLeft(ByRef src_i32 As Long, ByVal src_nobits As Long) As Long
Static bit0 As Long
Static i As Long
Static bitmask As Long
Static topbit As Long
Static aLong As Long
Static no_saved_bits As Long
If src_nobits < 0 Or src_nobits > 32 Then
Err.Raise 5, "i32_ShiftLeft", "bit number not in range [0..32)"
End If
If src_nobits = 0 Then ' no shifting, zero bitshift requested :)
i32_ShiftLeft = src_i32
Exit Function
End If
If src_nobits = 32 Then ' full longword bitshift requested, hence will be zero :)
i32_ShiftLeft = &H0&
Exit Function
End If
' the damn sign bit stuffs things up/
' calc how many bits are to be saved (from bit0) and create a bitmask
no_saved_bits = 31 - src_nobits ' remember this is zero-based so 0 result means there is 1 bit to be saved
bitmask = 0
For i = 0 To no_saved_bits - 1 ' no_saved_bits=0 means move 31 bits to the left, and this FOR LOOP gets skipped :)
bitmask = bitmask Or i32_bitarray(i)
Next i
' mask them in (ie mask out the bits to be lost), shift them left, and put in the sign bit
aLong = src_i32 And bitmask
aLong = aLong * (2& ^ src_nobits)
topbit = IIf((src_i32 And i32_bitarray(no_saved_bits)) = i32_bitarray(no_saved_bits), i32_bit_31, 0)
aLong = aLong Or topbit
i32_ShiftLeft = aLong
End Function
|
|
|
|
|
Sorry, like many here I get as far as seeing VB6 and stop reading. You are posting to a site that is VERY .net centric so I doudt you will get a satisfactory response.
Do you really expect someone to read through the code dump.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
OK thanks for clarifying that it's a .net-centric site. I'd hoped the forum was able to help, but never mind, it was worth a try. No not expected anyone to read the code other than prompting a bite (pun intentional) from a techo who'd be interested in something esoteric - which is the focus of the problem, really.
Oh well... probably means off to learn Java. Although I do recall a long time ago someone said something about inline assembler in VB6 I'll Google it but don't hope for anything since long searching on VB6 bit operations yielded next to nothing.
Not aware of any "ordinary" Win32 calls available to do bitwise shift/rotate/compare operations ?
|
|
|
|
|
halsboss wrote: Not aware of any "ordinary" Win32 calls available to do bitwise shift/rotate/compare operations ?
There are none considering Win32 is written in C and Intel x86 Assembler and those languages handle all that stuff natively.
VB6 does not natively support inline assembler. It requires an IDE plugin or some other "hack" to get working. Google for "vb6 inline asm" for clues.
You'll have to write the functions to do it in VB6 yourself. Bitwise operations are just small math problems. Or, you could write equivilent functions in C and compile that to a .DLL which your VB6 code could import and use.
Oh, BTW, bitwise operations are also native in C# and VB.NET.
|
|
|
|
|
Why don't you use C++ , for instance?
Or cannot you build a C DLL for parsing frames and make it available to your VB6 app?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
no C, stuck with VB6, have to code my own bitstream functions by the looks. damnation.
|
|
|
|
|