在VB.NET中进行类型转换的问题? [英] ??problems typecasting in VB.NET??

查看:68
本文介绍了在VB.NET中进行类型转换的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我在尝试在VB.Net中输入强制转换时遇到问题。我想用16位无符号整数读取

并将其转换为带符号的16位
整数。我正在使用以下代码行:


Dim wordVal As Short


wordVal = CShort(Val(input.Text))

output.Text = wordVal


每当input.Text 32767,我都会遇到运行时错误。寻找一些

的建议。


提前致谢,

-weg

解决方案

尝试BitConverter类


-
http://www.alvas.net - C#和VB.Net开发人员的音频工具

< we *** @ drexel埃杜??????? / ???????? ? ???????? ?????????:

新闻:11 ********************* @ v23g2000prn.googlegro ups.com。 ..


大家好,


我在尝试在VB.Net中输入强制转换时遇到问题。我想用16位无符号整数读取

并将其转换为带符号的16位
整数。我正在使用以下代码行:


Dim wordVal As Short


wordVal = CShort(Val(input.Text))

output.Text = wordVal


每当input.Text 32767,我都会遇到运行时错误。寻找一些

的建议。


提前致谢,

-weg


< we *** @ drexel.eduschrieb


大家好,


我在尝试在VB.Net中输入强制转换时遇到问题。我想用16位无符号整数读取

并将其转换为带符号的16位
整数。我正在使用以下代码行:


Dim wordVal As Short


wordVal = CShort(Val(input.Text))

output.Text = wordVal


每当input.Text 32767,我都会遇到运行时错误。寻找

一些建议。



我不确定你要做什么。如果你想输入值32767,

为什么不使用不同的数据类型呢?

Armin


< blockquote>我不确定你要做什么。如果要输入值32767,


为什么不使用不同的数据类型?


我不确定你要做什么。如果你想输入值32767,

为什么不使用不同的数据类型?


Armin



要从unsigned int转换为signed int,代码会读取

这样的东西:


如果unsignedInt 32767那么

signedInt = unsignedInt - 65535

否则

signedInt = unsignedInt

结束如果


我想通过类型转换进行上述转换,所以每次读入值时,我都没有

来调用上面的函数。我会

而是做类似的事情:


signedInt = CShort(unsignedInt)


但是我得到溢出错误。


Hi all,

I''m having problems trying to type cast in VB.Net. I''d like to read
in a 16 bit unsigned integer and convert it to a signed 16 bit
integer. I''m using the following line of code:

Dim wordVal As Short

wordVal = CShort(Val(input.Text))
output.Text = wordVal

Whenever input.Text 32767, I get a run-time error. Looking for some
suggestions.

Thanks in advance,
-weg

解决方案

Try BitConverter class

--
http://www.alvas.net - Audio tools for C# and VB.Net developers
<we***@drexel.edu???????/???????? ? ???????? ?????????:
news:11*********************@v23g2000prn.googlegro ups.com...

Hi all,

I''m having problems trying to type cast in VB.Net. I''d like to read
in a 16 bit unsigned integer and convert it to a signed 16 bit
integer. I''m using the following line of code:

Dim wordVal As Short

wordVal = CShort(Val(input.Text))
output.Text = wordVal

Whenever input.Text 32767, I get a run-time error. Looking for some
suggestions.

Thanks in advance,
-weg



<we***@drexel.eduschrieb

Hi all,

I''m having problems trying to type cast in VB.Net. I''d like to read
in a 16 bit unsigned integer and convert it to a signed 16 bit
integer. I''m using the following line of code:

Dim wordVal As Short

wordVal = CShort(Val(input.Text))
output.Text = wordVal

Whenever input.Text 32767, I get a run-time error. Looking for
some suggestions.

I''m not sure what you are trying to do. If you want to input values 32767,
why not use a different data type?
Armin


I''m not sure what you are trying to do. If you want to input values 32767,

why not use a different data type?

I''m not sure what you are trying to do. If you want to input values 32767,
why not use a different data type?

Armin

To convert from an unsigned int to a signed int, the code would read
something like this:

If unsignedInt 32767 Then
signedInt = unsignedInt - 65535
Else
signedInt = unsignedInt
End If

I would like to do the above conversion by typecasting so I don''t have
to call a function like above every time I read in a value. I would
rather do something like:

signedInt = CShort(unsignedInt)

but I get an overflow error.


这篇关于在VB.NET中进行类型转换的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆