Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Equivalent code in vb6 ???


VB
Dim d1 As UInteger
Dim d2 As UInteger
Dim d3 As UInteger
Dim d4 As UInteger
Dim d5 As UInteger
Dim d6 As UInteger
Dim i2c_address As Byte = &H53



If i2c_Initialize(I2CIRQ_DISABLE) = False Then
    Console.Write("FALSE!!  {0}" & vbLf, roboio_GetErrMsg())
    Return -1
End If


i2c0_SetSpeed(I2CMODE_FAST, 400000L)

i2c0master_StartN(i2c_address,I2C_WRITE,2) 'write 2 byte
i2c0master_WriteN(&H2d) 'Pwoer_Control register
i2c0master_WriteN(&H28) 'link and measure mode

wait_ms(100)

i2c0master_StartN(i2c_address,I2C_WRITE,2) 'write 2 byte
i2c0master_WriteN(&H31) 'Data_Format register
i2c0master_WriteN(&H08) 'Full_Resolution

wait_ms(100)

i2c0master_StartN(i2c_address,I2C_WRITE,2) 'write 2 byte
i2c0master_WriteN(&H38) 'FIFO_Control register
i2c0master_WriteN(&H00) 'bypass mode

wait_ms(100)

Do
    i2c0master_StartN(i2c_address, I2C_WRITE, 1)
    i2c0master_SetRestartN(I2C_READ, 6)
    i2c0master_WriteN(&H32) 'Read from X register (Address : 0x32)
    d1 = i2c0master_ReadN() 'X LSB
    d2 = i2c0master_ReadN() 'X MSB
    d3 = i2c0master_ReadN() 'Y LSB
    d4 = i2c0master_ReadN() 'Y MSB
    d5 = i2c0master_ReadN() 'Z LSB
    d6 = i2c0master_ReadN() 'Z MSB

    Console.Write("Acc of X-axis :{0,5:D}" & vbLf, If(((d2 And &H80) <> 0), ((((Not 0))>>16)<<16) Or ((d2<<8)+d1), (d2<<8)+d1))
    Console.Write("Acc of Y-axis :{0,5:D}" & vbLf, If(((d4 And &H80) <> 0), ((((Not 0))>>16)<<16) Or ((d4<<8)+d3), (d4<<8)+d3))
    Console.Write("Acc of Z-axis :{0,5:D}" & vbLf, If(((d6 And &H80) <> 0), ((((Not 0))>>16)<<16) Or ((d6<<8)+d5), (d6<<8)+d5))

    wait_ms(100)
Loop While Console.ReadKey(True).KeyChar <> 27

i2c_Close()
Return 0
Posted
Updated 2-Jun-12 20:23pm
v3
Comments
Sergey Alexandrovich Kryukov 3-Jun-12 3:15am    
Why?! why?
--SA

Why not just download Visual Studio Express and use a modern language instead of the dead VB6??

Since VB6 doesn't target building console apps, doesn't support unsigned integers, and we have no idea what kind of library your i2c stuff is using, there really isn't a direct conversion.

Everything else is just knowing what the operators do and replacing those VB6 doesn't support (like the << and >> bit shift operators) with an appropriate math function.
 
Share this answer
 
Agree with Dave. Start with VB.NET instead of VB6. See the below blog post for more details(code conversion & why no to VB6)

.NET Code Conversion - Convert your code[^]

I'm back at Q/A section after around 3 months
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900