乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 76|回复: 4

请问如何解决"当随机文件中的字段包含有汉字,则此字段之后的字段内容无法显

[复制链接]

15

主题

37

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
97
发表于 2004-2-9 10:55:00 | 显示全部楼层 |阅读模式
请问如何解决"当随机文件中的字段包含有汉字,则此字段之后的字段内容无法显示在列表框中"这一问题?[br]请看下面的程序段落
----------------------------------------------
'定义用户自定义类型
Private Type SubstationDataGather_Type
                         Substation_Name As String * 20
                         Substation_Alias As String * 20
                         HighTensionCable_SegmentNumber As Integer
                         SumRb As Double
                         SumXb As Double
End Type
Dim SubstationDataGather_DataArray() As SubstationDataGather_Type
'在窗体初始化过程中把随机文件中的每一记录的各字段连接成一字符串,显示在列表框中
For RecordNumber = 1 To Lastrec
                               
                                                                 Get #1, RecordNumber, SubstationDataGather_DataArray(RecordNumber)
                                                                 With SubstationDataGather_DataArray(RecordNumber)
                                                                               
                                                                                                                        SubstationDataGatherList = Format(.Substation_Name, "@@@@@@@@@@@@@@@@@@@@") & "                         " & _
                                                                                                                                                                                                                                                                                                                                         Format(.Substation_Alias, "@@@@@@@@@@@@@@@@@@@@") & _
                                                                                                                                                                                                                                                                                                                                         Format(.HighTensionCable_SegmentNumber, "##") & "                                                                                                                 " & _
                                                                                                                                                                                                                                                                                                                                         Format(Val(.SumRb), "##.#####") & "                         " & _
                                                                                                                                                                                                                                                                                                                                         Format(Val(.SumXb), "##.#####")
                                                                                                                                                                                                                                                                                               
                                                                                        End With
                                                                                 
                                                                         '向列表框1中添加数据项, 即把数据显示在列表框1中
                                                                         ListBox1.AddItem SubstationDataGatherList
                                         Next RecordNumber
-----------------------------------------------------------------------------------------------
对于上面的程序段落,当随机文件中的某一记录的字段包含有汉字,则此字段之后的字段内容无法显示在列表框中,在列表框中显示如:
“2631变电所                                                                                                                                                                                                                                                                                                                                                 ”
而实际应显示为:
“2631变电所                         2631                                 1                          2.3333                                 0.33333                                        ”
请问如何解决?
回复

使用道具 举报

158

主题

2315

帖子

10

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2951
发表于 2004-2-9 13:02:00 | 显示全部楼层
你文本文件中的行文字是怎样转换到自定义数据类型SubstationDataGather_Type中的呢?
回复

使用道具 举报

15

主题

37

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
97
发表于 2004-2-9 19:49:00 | 显示全部楼层
谢谢mccad 老师的关注。文本文件中的行文字是通过以下程序转换到自定义数据类型SubstationDataGather_Type中的,恳请mccad 老师指正。
Dim Lastrec As Integer
                                         Dim RecordNumber As Integer
                                         Dim SubstationDataGatherList As String
                                                On Error Resume Next
                                               
                                         ReDim Preserve SubstationDataGather_DataArray(0)
                                         
                                         '以随机访问方式打开文件
                                         Open "f:\MyAutoCAD\MyVBA\SubstationDataGather.dat" For Random As #1 Len = Len(SubstationDataGather_DataArray(0))
                                                                                               
                                         Lastrec = LOF(1) / Len(SubstationDataGather_DataArray(0))
                                               
                                         ReDim Preserve SubstationDataGather_DataArray(Lastrec)
                                         '清空列表框1,为在其中显示全部记录做准备
                                         ListBox1.Clear
                                         
                                         
                                         '通过循环,把打开的硬盘上的文件"f:\MyAutoCAD\MyVBA\SubstationDataGather.dat"中的记录
                                         '一一赋予SubstationDataGather_Array()数组,再把数组中的数据一一加入到列表框中1显示出来
                                         
For RecordNumber = 1 To Lastrec
                               
                                                                 Get #1, RecordNumber, SubstationDataGather_DataArray(RecordNumber)
                                                                 With SubstationDataGather_DataArray(RecordNumber)
                                                                               
                                                                                                                        SubstationDataGatherList = Format(.Substation_Name, "@@@@@@@@@@@@@@@@@@@@") & "                         " & _
                                                                                                                                                                                                                                                                                                                                         Format(.Substation_Alias, "@@@@@@@@@@@@@@@@@@@@") & _
                                                                                                                                                                                                                                                                                                                                         Format(.HighTensionCable_SegmentNumber, "##") & "                                                                                                                 " & _
                                                                                                                                                                                                                                                                                                                                         Format(Val(.SumRb), "##.#####") & "                         " & _
                                                                                                                                                                                                                                                                                                                                         Format(Val(.SumXb), "##.#####")
                                                                                                                                                                                                                                                                                               
                                                                                        End With
                                                                                 
                                                                         '向列表框1中添加数据项, 即把数据显示在列表框1中
                                                                         ListBox1.AddItem SubstationDataGatherList
                                         Next RecordNumber
'关闭文件
Close #1
回复

使用道具 举报

158

主题

2315

帖子

10

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2951
发表于 2004-2-9 20:36:00 | 显示全部楼层
我这里没有你所说的问题,以下是我试验的代码:
  1. Dim SubstationDataGather_DataArray As SubstationDataGather_Type
  2. Private Sub CommandButton1_Click()
  3.        Open "d:\Gather.dat" For Random As #1 Len = Len(SubstationDataGather_DataArray)
  4.        Get #1, 1, SubstationDataGather_DataArray
  5.        Close #1
  6.        With SubstationDataGather_DataArray
  7.                SubstationDataGatherList = Format(.Substation_Name, "@@@@@@@@@@@@@@@@@@@@") & "       " & _
  8.                                                                      Format(.Substation_Alias, "@@@@@@@@@@@@@@@@@@@@") & _
  9.                                                                      Format(.HighTensionCable_SegmentNumber, "##") & "                             " & _
  10.                                                                      Format(Val(.SumRb), "##.#####") & "       " & _
  11.                                                                      Format(Val(.SumXb), "##.#####")
  12.        End With
  13.        '向列表框1中添加数据项, 即把数据显示在列表框1中
  14.        ListBox1.AddItem SubstationDataGatherList
  15. End SubPrivate Sub UserForm_Initialize()
  16.        Open "d:\Gather.dat" For Random As #1 Len = Len(SubstationDataGather_DataArray)
  17.        With SubstationDataGather_DataArray
  18.                .Substation_Name = "2631变电所"
  19.                .Substation_Alias = "2631"
  20.                .HighTensionCable_SegmentNumber = 1
  21.                .SumRb = 2.3333
  22.                .SumXb = 2.3333
  23.        End With
  24.        Put #1, 1, SubstationDataGather_DataArray
  25.        Close #1
  26. End Sub
回复

使用道具 举报

15

主题

37

帖子

4

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
97
发表于 2004-2-10 12:02:00 | 显示全部楼层
mccad 老师,当我使用“逐语句”的方法运行我上面列出的程序时,在执行到包含有汉字的记录时,我把光标放在“ListBox1.AddItem SubstationDataGatherList”语句行的“SubstationDataGatherList”字符上,则此时能够出现如“2631变电所                         2631                                 1                          2.3333                                 0.33333                                        ”这样的正确提示值,但在列表框中就出现上面所述的错误显示,请问mccad 老师如何解决?
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 13:01 , Processed in 0.487063 second(s), 62 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表