我试图尝试JaredPar ByRef和ByVal Clarification所回答的问题
ByVal在VB.NET中意味着将提供的值的副本发送到该函数.对于值类型(Integer,Single等),这将提供值的浅表副本.对于较大的类型,这可能是低效的.对于引用类型(String,类实例),传递引用的副本.因为副本通过突变传递给参数,=所以调用函数不会看到它.
ByRef在VB.NET中意味着对原始值的引用将被发送到函数(1).它几乎就像在函数中直接使用原始值.类似的操作=会影响原始值并在调用函数中立即可见.
我试着用以下代码测试它,我似乎无法让它工作使用ByRef更改单元格的值,0如果它是1
这是我正在测试的下面的代码,我做错了什么?价值Range("A1")仍然是1
Sub test1()
Dim trythis As Boolean
trythis = False
If (Sheets("TESTING").Range("A1").value = 1) Then
testingRoutine (trythis)
If (trythis) Then
Debug.Print "Value changed to 0"
Sheets("TESTING").Range("A1").value = 0
End If
End If
End Sub
Private Function testingRoutine(ByRef trythis As Boolean)
Debug.Print "Ran Function"
trythis = True
End Function
Run Code Online (Sandbox Code Playgroud) 介绍
我正在尝试删除一行,如果在该数组中找到该行的值.
这些值将输入到Userform上的TextBox中,每个值由该NewLine字符分隔.
我想我已经设法确定逻辑在Split()函数中是错误的.从在线研究中,我看到人们使用......
Split(text, Chr(10))
Split(text, Chr(16))
Split(text, vbLf)
Run Code Online (Sandbox Code Playgroud)
这些数值无(Chr(10),Chr(16),vbLf)似乎正在按原计划...什么似乎是发生的是,它会找到的NewLine字符,但它不是从字符串中取出,并保持价值时放入数组中.
码
填写数据......
data() = Split(frmDeleteLines.textData, Chr(10))
''''' Also tested Chr(16) and vbLf
Run Code Online (Sandbox Code Playgroud)
删除行...
Private Sub DeleteLines(textArr() As String, column As Long)
Dim LR As Long
LR = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).row
With ActiveSheet
For i = LR To 3 Step -1
If Not (SearchArray(.Cells(i, column), textArr())) Then '<--- Call search array
.Cells(i, column).EntireRow.Delete 'Delete row if found
End If …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个包含数组的类,我遇到了为它创建类的问题......
类:
Private pST(0 To 2) As String
Public Property Get ST() As String
ST() = pST()
End Property
Public Property Let ST(value() As String) '<---- ERROR HERE
pST() = value()
End Property
Run Code Online (Sandbox Code Playgroud)
代码运行:
Sub test()
Dim foo As cPurchaseOrder
Set foo = New cPurchaseOrder
foo.ST(0) = "test"
Debug.Print foo.ST(0)
End Sub
Run Code Online (Sandbox Code Playgroud)
错误:
编译错误:
相同属性的属性过程的定义不一致,或者属性过程具有可选参数,ParamArray或无效的Set final参数.
问题:
如何使用数组作为变量正确初始化类?
编辑: 关于Mat的Mug响应
课程已更改:
Private pST As Variant
Public Property Get STContent(ByVal index As Long) As String
STContent = pST(index)
End Property
Public …Run Code Online (Sandbox Code Playgroud) 我试图Collection从函数返回类型,但收到错误:
编译错误:
无效使用财产
这是我为测试该功能而创建的以下代码。我知道集合填充正确,因为我已经测试了集合的运行并输出所有值;一切都按预期进行。
问题:
为什么会出现这个错误?修复它的最佳方法是什么?
Sub testingFunc()
Dim ErrorCodes As Collection
Set ErrorCodes = New Collection
Set InitializeErrorCodes = ErrorCodes '<--- Where my error is occurring when trying to retrieve the collection
End Sub
Run Code Online (Sandbox Code Playgroud)
这是初始化我的代码Error Codes
Function InitializeErrorCodes() As Collection '<--- Where I'm trying to return the collection
Dim ErrorCodes As Collection
Set ErrorCodes = New Collection
AddToErrorCollection ErrorCodes, "CSD_ERR_120", "Multiple products in a case is invalid"
AddToErrorCollection ErrorCodes, "CSD_ERR_128", "Invalid Store with Zero Allocation"
AddToErrorCollection …Run Code Online (Sandbox Code Playgroud) 我尝试在线复制一些代码,我从下面链接中找到... http://www.ozgrid.com/forum/showthread.php?t=15325
我尝试使用一些代码通过我的Excel工作簿中的按钮导入图像,这段代码锁定了我的工作表,当它提示输入密码时,我试着点击输入而没有占优势......
我在下面使用的代码
Sub BrowsePicture()
Dim Pict
Dim ImgFileFormat As String
Dim PictCell As Range
Dim Ans As Integer
ActiveSheet.Protect True, True, True, True, True
ImgFileFormat = "Image Files (*.bmp),others, tif (*.tif),*.tif, jpg (*.jpg),*.jpg"
GetPict:
Pict = Application.GetOpenFilename(ImgFileFormat)
'Note you can load in any nearly file format
If Pict = False Then End
Ans = MsgBox("Open : " & Pict, vbYesNo, "Insert Picture")
If Ans = vbNo Then GoTo GetPict
'Now paste to userselected cell
GetCell:
Set PictCell = …Run Code Online (Sandbox Code Playgroud)