为什么这个VBA打印出随机垃圾? [英] Why does this VBA print out random garbage?

查看:171
本文介绍了为什么这个VBA打印出随机垃圾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个VBA功能打印出字符串末尾的随机垃圾

Why does this VBA function print out random garbage at the end of the string?

Public Function GenGuid() As String
    Dim TypeLib As Object
    Dim Guid As String
    Set TypeLib = CreateObject("Scriptlet.TypeLib")
    Guid = TypeLib.Guid
    ' format is {24DD18D4-C902-497F-A64B-28B2FA741661}
    Guid = Replace(Guid, "{", "")
    Guid = Replace(Guid, "}", "")
    'Guid = Replace(Guid, "-", "")
    GenGuid = Guid
End Function

print genguid()
816BF7CB-68B9-4D6B-855B-1273F22063DB 6
print genguid()
53664789-B0CD-422C-87B4-8928D93E5078  
print genguid()
FDD8ABDE-41F1-45E0-8330-9BA6161873BE i



参考



http://office.microsoft.com/client/helppreview.aspx?AssetId=HV805572319990&lcid=1033&NS=EXCEL%2EDEV&Version=12&queryid=&respos=1&HelpID=vblr6%2Echm1008930

Reference

http://office.microsoft.com/client/helppreview.aspx?AssetId=HV805572319990&lcid=1033&NS=EXCEL%2EDEV&Version=12&queryid=&respos=1&HelpID=vblr6%2Echm1008930

Excel 2007

Excel 2007

推荐答案

这是一个长期存在的GUID错误,已经记录了很久。这是一个空的终止的排序,它应该在两个地方以ASC(0)结束。我在Excel立即窗口中测试了它,第二个垃圾数字循环遍历不同的值,只有第一个空字符始终为空。

It's a long-standing GUID bug that has been documented for quite some time. It's a null termination of sorts, and it should be ending with ASC(0) in both places. I tested it out in the Excel immediate window and the second "garbage" digit cycles through different values and only the first null character is consistently null.

一旦函数被调用然而,从一个单元格中,在立即窗口中打印它不再会调用不同的最后一个数字,并会一直打印出两个ASC(0)值。奇怪的。

Once the function is called from a cell, however, printing it in the immediate window ceases to call a different last digit, and will consistently print out two ASC(0) values instead. Weird.

只要我测试过,修剪最后2个地方,不会显示任何有害的影响。

Trimming the last 2 places, however, does not show any harmful effects, as far as I've tested.

这篇关于为什么这个VBA打印出随机垃圾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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