繁体   English   中英

'无法将'System.String'类型的对象转换为'System.Array'类型。' VB.net

[英]'Unable to cast object of type 'System.String' to type 'System.Array'.' vb.net

我正在尝试获取单元格值的左侧字符并查看它是否小于一个字符,如果是则在末尾添加两个字符(“FE”)。 我的问题似乎与将字符串转换为数组有关。 我假设我为此使用了错误的功能,但我不知道。 任何提示都会很棒。 作为参考,EC80 ("A" & i)是 hex_value 的值。 当它完成最后一个 If 语句时,它应该是 ECFE。

'Convert HEX values to acronyms
        Dim unique_numbers As Object
        unique_numbers = xlWorkBook.Sheets("Unique Numbers")
        Dim i As Integer
        Dim hex_value As Object
        i = 2 'Starting from two since the first row is the header
        Do Until unique_numbers.Range("A" & i) Is ""
            hex_value = unique_numbers.Range("A" & i).Value
            'unique_numbers.Range("A" & i) = convert_hex_to_acronym(unique_numbers.Range("A" & i))
            i = i + 1
            If hex_value = "0" Then
                hex_value = "0000"
            End If

            'If the first character of the string is < "F",
            'reconstruct the string by taking the first two characters and adding "FE" before comparing it.
            If LBound(hex_value, 1) < "F" Then 'Where the error occurs. hex_value = EC80(which is correct).
                hex_value = LBound(hex_value, 2) & "FE" 'hex_value should = ECFE after.
            End If
        Loop
'If the first character of the string is < "F",'reconstruct the string by taking the first two characters and adding "FE" before comparing it.
 If Strings.Left(hex_value, 1) < "F" 
    hex_value = Strings.Left(hex_value, 2) & "FE"
 End If

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM