Hi All,
Consider the following code.
Dim str As String
Dim i As Integer
str = " Hello Hi"
If str.IndexOf("Ab c Def") Or str.IndexOf("Gh i jkl mno") Or _
str.IndexOf("pq r stu vwxe") Or str.IndexOf("er rr erttt. tttt")
Or _
str.IndexOf("gf gh fgfg fgfhe") Or str.IndexOf("fg Cghr hggh.
sds") Or _
str.IndexOf("sd s sd dfd dfd dfd") Or str.IndexOf("df d dfd dfd
dfdf") Or _
str.IndexOf("df ds qwq cvb") Or str.IndexOf("jh jhy hjht") Or _
str.IndexOf("hj jyy Lyy") Or str.IndexOf("ty tl jjj") Or _
str.IndexOf("we w vbn ghg ghg") Or str.IndexOf("gh gj ghhe hhj hjh
gh ghjg") Or _
str.IndexOf("gh jg gh. ghj. gh") Or _
str.IndexOf("gh ghjg") > -1 Then
MsgBox("Found", MsgBoxStyle.OKO nly)
Else
MsgBox("Not Found", MsgBoxStyle.OKO nly)
End If
i = str.IndexOf("Ab c Def")
MsgBox(i, MsgBoxStyle.OKO nly)
If i > -1 Then
MsgBox("False", MsgBoxStyle.OKO nly)
Else
MsgBox("True", MsgBoxStyle.OKO nly)
End If
Though the first condition returns -1, "Found" is diplayed. However 'i'
contains -1 and the second condition is executed correctly and "True" is
displayed!
Could anybody please explain as to why the first condition returned true?
Thanks.
kd. 2 4215
Hi,
Dont let vb.net convert an integer to a boolean add > -1 to each
str.Indexof statement.
Ken
---------------
"kd" <kd@discussions .microsoft.com> wrote in message
news:E7******** *************** ***********@mic rosoft.com...
Hi All,
Consider the following code.
Dim str As String
Dim i As Integer
str = " Hello Hi"
If str.IndexOf("Ab c Def") Or str.IndexOf("Gh i jkl mno") Or _
str.IndexOf("pq r stu vwxe") Or str.IndexOf("er rr erttt. tttt")
Or _
str.IndexOf("gf gh fgfg fgfhe") Or str.IndexOf("fg Cghr hggh.
sds") Or _
str.IndexOf("sd s sd dfd dfd dfd") Or str.IndexOf("df d dfd dfd
dfdf") Or _
str.IndexOf("df ds qwq cvb") Or str.IndexOf("jh jhy hjht") Or _
str.IndexOf("hj jyy Lyy") Or str.IndexOf("ty tl jjj") Or _
str.IndexOf("we w vbn ghg ghg") Or str.IndexOf("gh gj ghhe hhj hjh
gh ghjg") Or _
str.IndexOf("gh jg gh. ghj. gh") Or _
str.IndexOf("gh ghjg") > -1 Then
MsgBox("Found", MsgBoxStyle.OKO nly)
Else
MsgBox("Not Found", MsgBoxStyle.OKO nly)
End If
i = str.IndexOf("Ab c Def")
MsgBox(i, MsgBoxStyle.OKO nly)
If i > -1 Then
MsgBox("False", MsgBoxStyle.OKO nly)
Else
MsgBox("True", MsgBoxStyle.OKO nly)
End If
Though the first condition returns -1, "Found" is diplayed. However 'i'
contains -1 and the second condition is executed correctly and "True" is
displayed!
Could anybody please explain as to why the first condition returned true?
Thanks.
kd.
To add to what Ken has said, Option Strict On would tell you you are
doing something wrong here. Integers should not be trated as
truth-values - yes VB6 let you do this, but it's not 'Strict'ly (haha)
correct...
--
Larry Lard
Replies to group please
Ken Tucker [MVP] wrote: Hi,
Dont let vb.net convert an integer to a boolean add > -1 to
each str.Indexof statement.
Ken --------------- "kd" <kd@discussions .microsoft.com> wrote in message news:E7******** *************** ***********@mic rosoft.com... Hi All,
Consider the following code.
Dim str As String Dim i As Integer str = " Hello Hi" If str.IndexOf("Ab c Def") Or str.IndexOf("Gh i jkl mno") Or _ str.IndexOf("pq r stu vwxe") Or str.IndexOf("er rr erttt.
tttt") Or _ str.IndexOf("gf gh fgfg fgfhe") Or str.IndexOf("fg Cghr
hggh. sds") Or _ str.IndexOf("sd s sd dfd dfd dfd") Or str.IndexOf("df d dfd
dfd dfdf") Or _ str.IndexOf("df ds qwq cvb") Or str.IndexOf("jh jhy hjht")
Or _ str.IndexOf("hj jyy Lyy") Or str.IndexOf("ty tl jjj") Or _ str.IndexOf("we w vbn ghg ghg") Or str.IndexOf("gh gj ghhe
hhj hjh gh ghjg") Or _ str.IndexOf("gh jg gh. ghj. gh") Or _ str.IndexOf("gh ghjg") > -1 Then MsgBox("Found", MsgBoxStyle.OKO nly) Else MsgBox("Not Found", MsgBoxStyle.OKO nly) End If
i = str.IndexOf("Ab c Def") MsgBox(i, MsgBoxStyle.OKO nly) If i > -1 Then MsgBox("False", MsgBoxStyle.OKO nly) Else MsgBox("True", MsgBoxStyle.OKO nly) End If
Though the first condition returns -1, "Found" is diplayed. However
'i' contains -1 and the second condition is executed correctly and "True"
is displayed!
Could anybody please explain as to why the first condition returned
true? Thanks. kd. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: David Taylor |
last post by:
In .net I am using a HttpWebRequest to read from a WebSite. I am getting
everything back except for some characters above hex 7F which appear to have
been stripped out of my response. I see these characters if I examine the
site with IE.
It has been suggested that this is an encoding problem, but I'm unsure as
what I need to do about it. Can anybody help?
|
by: Vigneshwar Pilli via DotNetMonster.com |
last post by:
Hey,
Well, I have a Problem.
I have designed a table which has few fields which are being declared in
the database of type ....
char of length 10.
and other fields with varchar 50 and datetime too.
Well, the Problem is I am not able to display the CHAR type FIELDS in the
|
by: Ankit Aneja |
last post by:
I put the code for url rewrite in my Application_BeginRequest on global.ascx
some .aspx pages are in root ,some in folder named admin and some in folder
named user
aspx pages which are in user folder are using this code of url rewrite
project is running completely fine on localhost
but after uploading first page
(http://emailware.net.temporary.domain.name/user/index.aspx) is fine
but as i click
123 Easy-CD Ripper
|
by: tangus via DotNetMonster.com |
last post by:
Hello all, I'm really struggling with getting some Active Directory code to
work in ASP.NET. Can you please provide assistance? I am executing the
following code:
Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://domain")
Dim mySearcher As New DirectorySearcher(enTry)
Dim resEnt As SearchResult
mySearcher.Filter = ("(objectClass=*)")
mySearcher.SearchScope = SearchScope.Subtree
|
by: Cor |
last post by:
Hallo,
I have promised Jay B yesterday to do some tests.
The subject was a string evaluation that Jon had send in. Jay B was in doubt
what was better because there was a discussion in the C# newsgroup on 25
September. The regular expressions where in that newsgroup too involved.
I told yesterday night, to Jay that I would test all 4 methods and the
stupid method I was thinking of the first time that night when I saw Jon's
| |
by: Richard L Rosenheim |
last post by:
I'm having a problem with IndexOf on a large string. The string contains an
ASCII file which is about 45K. IndexOf is not finding substrings that I
know are in the string. Yes, I double-checked my typing. I'm also able to
locate the strings using a text editor. One substring is about 38K
characters into the string.
Is there any know issues, limitations, etc. with IndexOf that I may not be
aware of?
I'm working with a VB.Net using...
|
by: exekutive |
last post by:
I've been wrestling with this programming problem for some time now, so I
thought I'd put it up for discussion. I'm trying to design a Mask function.
See if you can figure out a code for it...
The best way to explain this is to give an example of what the functions
should do.
* Let us a define a function as follows:
Public Function Mask(ByRef inputStr As String, ByRef maskInStr As
|
by: sunita jadhav |
last post by:
my question is if i type in html textbox on key press event suppose i type 12345 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i have face problem that is if i insert 6 at 3 this value is not insert at 3 it insert last positon i.e after last value .In given example the value is appned or insert after 5 then output is 12456 but i have want the output 12645 and i also give the...
|
by: Iridium |
last post by:
Greetings,
I am trying to get a JPG Frame from a MJPG Stream. A MJPG is basically a stream of JPGs which are splitted by a special boundary string. So I tried to get the stream, split it by the boundary strings and save the JPG binary data into a file.
The problem is, I cant save the data into a proper JPG file which I then open. This is my code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |