Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

シリアルポート自動取得 #40980

Closed
MATSUDA-YUJI opened this issue May 16, 2024 · 1 comment
Closed

シリアルポート自動取得 #40980

MATSUDA-YUJI opened this issue May 16, 2024 · 1 comment
Labels
dotnet-visualbasic/svc errors-warnings/subsvc Pri2 support-request Support-style question;customer needs help solving a problem [org][type][category]

Comments

@MATSUDA-YUJI
Copy link

Type of issue

Code doesn't work

Description

Dim SerialStr(4) As Byte '//CP2102のdefaultSerialは0001
SerialStr(0) = &H30
SerialStr(1) = &H30
SerialStr(2) = &H30
SerialStr(3) = &H31
Dspserialstr = ConvertToString(SerialStr(), 4) '// "0001"

BC30105 ERROR

[Enter feedback here]

Page URL

https://learn.microsoft.com/en-us/dotnet/visual-basic/misc/bc30105?f1url=%3FappId%3Droslyn%26k%3Dk(BC30105)#to-correct-this-error

Content source URL

https://github.com/dotnet/docs/blob/main/docs/visual-basic/misc/bc30105.md

Document Version Independent Id

ccf238a6-f40e-1998-e5de-565ba699ad33

Article author

@KathleenDollard

Metadata

  • ID: 3c99b034-3731-d8fc-231d-24d1e9cfe5ed
  • Service: dotnet-visualbasic
  • Sub-service: errors-warnings
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label May 16, 2024
@adegeo adegeo added the support-request Support-style question;customer needs help solving a problem [org][type][category] label May 27, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label May 27, 2024
@adegeo
Copy link
Contributor

adegeo commented May 27, 2024

Hello. This forum here isn't really for coding problems. I do suggest you try places like StackOverflow and Microsoft Q&A for coding language help. For help about array's, see Visual Basic Arrays.

It looks like you're trying to convert the array into a string. The method you used Convert.ToString(SerialStr(), 4) expects a single type, such as an individual Byte, to convert to a string. You're passing in SerialStr(), which is the array variable without a specific index, which is why the error appeared. You need to provide which individual array element you want to convert, such as SerialStr(1) or SerialStr(2).

It looks like you're putting in character codes, such as the physical character 0 and 1 into the array as bytes. A byte can be converted into a char then added to a string. This code should work. Notice I also changed SerialStr(4) to SerialStr(3). In VB you specify the array upper bound, not the array total number of elements. In other languages, like C#, you specify the total number.

Dim Dspserialstr As String
Dim SerialStr(3) As Byte
SerialStr(0) = &H30
SerialStr(1) = &H30
SerialStr(2) = &H30
SerialStr(3) = &H31

Dim builder As New System.Text.StringBuilder

For Each item In SerialStr
    builder.Append(Convert.ToChar(item))
Next

Dspserialstr = builder.ToString()
builder = Nothing

Console.WriteLine(Dspserialstr)

@adegeo adegeo closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet-visualbasic/svc errors-warnings/subsvc Pri2 support-request Support-style question;customer needs help solving a problem [org][type][category]
Projects
None yet
Development

No branches or pull requests

3 participants