vb6中的等效代码? [英] Equivalent code in vb6 ?
本文介绍了vb6中的等效代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
vb6中的等效代码???
Equivalent code in vb6 ???
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
推荐答案
为什么不只下载Visual Studio Express并使用现代语言代替废弃的VB6?
由于VB6并不针对构建控制台应用程序,也不支持无符号整数,而且我们不知道您的i2c东西正在使用哪种库,因此实际上并没有直接的转换.
其他一切都只是知道运算符在做什么,并用适当的数学函数替换那些不支持的VB6(例如<<>>位移位运算符).
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.
同意戴夫.从VB.NET而不是VB6开始.有关更多详细信息,请参见下面的博客文章(代码转换以及为什么不对VB6进行编码)
.NET代码转换-转换您的代码 [
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
这篇关于vb6中的等效代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文