gpt4 book ai didi

vb.net - 代码无缘无故停止工作。抛出一个缺失的成员异常......为什么?

转载 作者:行者123 更新时间:2023-12-03 08:51:57 25 4
gpt4 key购买 nike

我的代码突然停止工作。我收到此错误:

Microsoft.VisualBasic.dll 中出现“System.MissingMemberException”类型的未处理异常

附加信息:未找到类型“Double”的公共(public)成员“替换”。
此行出现错误“rCell.Value = rCell.Value.replace("PO", "")"

这是我的代码:

    Imports System.Data.Odbc
Imports System.Data.SqlClient
Imports System.IO.Directory
'Before you add this reference to your project,
' you need to install Microsoft Office and find last version of this file.
Imports Microsoft.Office.Interop.word
Imports Microsoft.Office.Interop
Imports System.Text.RegularExpressions


'=========================================================================ADDRESS FIXER===========================================================================
Public Class Form1

Public Address2Range As String
Public PoBoxFirst As String
Public NewAddress As String
Public rCell As Excel.Range
Public NewFirstHalf As String



Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

'------------------------------------------------------------------------Browse to Data File--------------------------------------------------------
Dim eXe As String = "C:\WORK\CHRIS_DATA_NOTES\BadAdds\BadAdds.xlsx"
'------------------------------------------------------------------Get the path they want to process
'Using tmpDlg As New OpenFileDialog
' tmpDlg.FileName = "C:\WORK\CHRIS_DATA_NOTES\BadAdds"
' While eXe Is Nothing
' If tmpDlg.ShowDialog = DialogResult.OK Then
' eXe = tmpDlg.FileName
' Else
' MsgBox("Please Select something.")
' Exit Sub
' End If
' End While
'End Using

'MsgBox(eXe)

Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value

xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(eXe)
xlWorkSheet = xlWorkBook.Sheets("sheet1")



Dim eColumn As Excel.Range = xlWorkSheet.Range("E2:E1559")
' Dim rCell As Excel.Range

'--------------------------------------------------------------Fixes PO Boxes-------------------------------------------------------------
For Each rCell In eColumn


If rCell.Value = "" Then
'Application.Exit()
Else

Dim PoBox
Dim PoBoxSearch = {"PO BOX", "P.O.", "O Box", "P0", "PO", "P.O. BOX", "Pox", "P 0", "P O ", "Pob", "PO B", "PO 8", "P0 B", "P O B", "P0B", "PO8", "P0B", "P OB", "PX", "POX", "PBX", "P0X", "PBOX", "P0BX", "PU", "O B"}
Dim PoList As List(Of String) = New List(Of String)(PoBoxSearch)
PoBox = rCell.Value.ToString()
PoBoxFirst = PoBox.Substring(0, 1)

If PoBoxFirst <> "p" Then
rCell.Value = rCell.Value.replace("Box", "")
rCell.Value = rCell.Value.replace("PO", "")
End If

For Each value In PoList

If PoBox.contains(value) Then

Dim Address As String
Address = rCell.Value.ToString()

Dim arySpaceFinder() As String
arySpaceFinder = Address.Split(" ")

'MsgBox(arySpaceFinder.Last())

If Char.IsLetter(arySpaceFinder.Last()) = True Then
'MsgBox("Has Letter")
' MsgBox(arySpaceFinder.Last())
rCell.Value = "PO Box " & arySpaceFinder.Last().Replace("I", "1")
rCell.Value = "PO Box " & arySpaceFinder.Last().Replace("O", "0")
rCell.Value = "PO Box " & arySpaceFinder.Last().Replace("X", "")
rCell.Value = "PO Box " & arySpaceFinder.Last().Replace("U", "O")
Else

'rCell.Value = "PO Box " & Address.Replace("PO", "").Replace("Box", "")
rCell.Value = "PO Box " & arySpaceFinder(0)
End If

rCell.Value = "PO Box " & arySpaceFinder.Last().Replace("I", "1").Replace("O", "0").Replace("X", "").Replace("Pob", "").Replace("U", "O")


End If
Next
End If

Next rCell


xlWorkSheet.SaveAs("C:\WORK\CHRIS_DATA_NOTES\BadAdds\Box_NEW.xlsx")
xlApp.Quit()
'Application.Exit()

End Sub

最佳答案

放在 try 语句中

         Try
If PoBoxFirst <> "p" Then
rCell.Value = rCell.Value.replace("Box", "")
rCell.Value = rCell.Value.replace("PO", "")
End If
Catch ex As Exception

End Try

关于vb.net - 代码无缘无故停止工作。抛出一个缺失的成员异常......为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com