在数组中使用instr()或mid()函数? [英] working with instr() or mid() functions in arrays?

查看:197
本文介绍了在数组中使用instr()或mid()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,mid函数不会比较两个数组的两个字符串。我真的不知道为什么!


如果我调试整个程序,我会看到字符串的正确部分,但程序没有进入if循环。


<我尝试使用Do Until-或者使用Instr() - 函数,但它不起作用。虽然循环也经过测试......现在我坐在这里几个小时但没有任何帮助。也许有人可以给我一个暗示。是不是可以使用这个函数
与数组?我也尝试使用过滤器,但这不是我需要的。



文件(0到300)作为字符串,文件名(1到300)作为字符串


'填充:文件(0)=" C:\ EmailAKWien.txt"  ;&NBSP;文件(1)=" C:\EmailAllianz.txt" ... ...


'填充:文件名(1)=" AKWien"   文件名(2)="安联" ...


对于x = 1到UBound(文件)

   对于pos = 1 To(Len(Files(x - 1)) - Len(Filename(v)))

       如果(文件名(v)=中(文件(x - 1),pos,Len(文件名(v)) - 1))那么


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; '为什么不将程序跳到这部分? &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;


               GoTo fillfiles

       结束如果是
   下一个

下一步


fillfiles:

解决方案

什么是v ?  您正在使用它作为数组的索引..



但是,您实际上在尝试做什么?  通常更好地描述您需要的内容,而不是显示不起作用的代码。如果您正在寻找名称"AKWien",在文件  "C:\\ \\EmailAKWien.txt"
 那么您只需进行比较,例如


如果文件(x)类似于"*" &安培;文件名(y)& " * QUOT;然后Msgbox"他们匹配!"



如果Instr(Files(x),Filename(y))> 0然后  Msgbox"他们匹配!"


My problem is, the mid function doesnt compare the two strings of the two arrays. I really dont know why!

If i debug the whole program i see the right part of the strings but the program doesnt go into the if loop.

i tried it with Do Until- or with the Instr()- function but it doesnt work. While loop was also tested... Now iam sitting here for hours but nothing helps. Maybe there is someone out there who could give me a hint. Isnt it possible to use this functions with an array? I tried also with Filter, but thats not that what i need.

Files (0 to 300) as string, Filename (1 to 300) as string

'filled with: Files(0)="C:\EmailAKWien.txt"   Files(1)="C:\EmailAllianz.txt" ...

'filled with: Filename(1)="AKWien"    Filename(2)="Allianz" ...

For x = 1 To UBound(Files)
    For pos = 1 To (Len(Files(x - 1)) - Len(Filename(v)))
        If (Filename(v) = Mid(Files(x - 1), pos, Len(Filename(v)) - 1)) Then

               'Why doesnt jump the program not into this part?             

               GoTo fillfiles
        End If
    Next
Next

fillfiles:

解决方案

What is v ?  You are using it as an index of the array..

But, what are you actually trying to do?  It is often better to describe what you need rather than show code that does not work. If you are looking for the name "AKWien" in the file "C:\EmailAKWien.txt"  then you would just a comparison such as

If Files(x) Like "*" & Filename(y) & "*" Then Msgbox "They match!"

Or

If Instr(Files(x),Filename(y)) > 0 Then Msgbox "They match!"


这篇关于在数组中使用instr()或mid()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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