|
Finding a sub-string within a string is easy. You just call String.IndexOf(). I showed you this before.
Dim myString As String = "I like www.google.com."<br />
If (myString.IndexOf("www.google.com") >= 0) Then<br />
' Found it!<br />
End If
Finding a particular string pattern such as an URL is a lot harder. This requires regular expression.
|
|
|
|
|
thanks Josh, but this doesn´t work or else i can´t put it working. Sorry but it´s already 5 am here and my brain is sleeping!
Can u PLEASE,HELP US!!!
Please do an example in the code that i gave u!!
THANKS!!!!!
-- modified at 23:57 Wednesday 18th January, 2006
|
|
|
|
|
No one here is going to do your homework for you.
But I'll give you some example code. It's up to you to figure out how to use it.
' Array of all URLs to search for.
Dim URLs() As String = {"google.com", _
"yahoo.com", _
"msn.com"}
Dim emailBody As String = "I like www.yahoo.com."
Dim urlName As String
Dim wasUrlFound As Boolean = False
' Traverse all known URLs.
For Each urlName In URLs
' Does this URL exist in the e-mail?
If (emailBody.IndexOf(urlName) >= 0) Then
wasUrlFound = True
Exit For
End If
Next
' Notify user if URL was found.
If (wasUrlFound) Then
MessageBox.Show("Found URL """ & urlName & """.")
End If
|
|
|
|
|
LONG LIVE Joshua Quick!!!!
Thanks a lot!!!
We will put your name in our work! :->
We breaked in the part of the search in the code, but you help us with your last response.
Once more, THANKS A LOT!!!!
|
|
|
|
|
Hi,
I have implemented a FolderBrowserDialog and it works fine except when it comes across long paths. Is there a way to pass the short version of the path to the FolderBrowserDialog when the folder is selected?
Thanks,
|
|
|
|
|
Zenly wrote: it works fine except when it comes across long paths.
Do you know why it doesn't work?
Have you tried putting double quotes around your path?
For example:
Dim path As String = """C:\Documents and Settings"""
Zenly wrote: Is there a way to pass the short version of the path
You can pass it as an 8 char long path name.
For example, the long path name to the following folder...
C:\Documents and Settings
...would turn out like this...
C:\Docume~1
I don't recommend that you construct the short path name yourself. Instead, PInvoke the Win32 function GetShortPathName().
|
|
|
|
|
The issue is not with the average long paths. But I have a path where each folder is 244 characters.
For example: H:\aaa...(244 char long)\bbb...(244 char long)\ccc...(244 char long)\
When the browse dialog opens and I drill down and click on the H:\aaa...(244 char long) folder it generates an exception at FolderBrowserDialog1.ShowDialog().
I am looking for a way so that I can use the GetShortPathName() fuction to get the shartpath and pass it to the dialog before the exception is generated.
Here is the code I am using...
Dim lvPath As String
FolderBrowserDialog1.SelectedPath = ""
FolderBrowserDialog1.ShowDialog()
If FolderBrowserDialog1.SelectedPath <> "" Then
strPath = FolderBrowserDialog1.SelectedPath
End If
Thanks,
|
|
|
|
|
The problem you're running into is a complete path cannot be more that 260(?) characters long. So in order for this to work, you'll have to shorten those folder names.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Has anyone used the menu control from The free Magic Library? I am having problems figuring out how to get it working.
I can post more if someone is out there that will be willing to help.
Thanks.
|
|
|
|
|
I'm willing . Tell me your problems.
|
|
|
|
|
Thanks for the help, I am a VB.net newbe.
I have a single form windows application that I
need a main menu control on it. I am currently
using the Magic Library 1.7.4 TabControl that
works great. I want to use their Menu Control
because it has the ability to add colors to the
menu and other features.
I can add the control to the form, I can add
the top level of commands to the
MenuCommand Collection Editor
but when I add the second level of commands
through the
MenuCommand Collection Editor
I get the following error when I close the
collection editor:
'Object reference not set to an instance
of an object'
I can't figure out what this is telling me.
I did try to add the MenuControl code but I was
totally lost. The documentation is not for the novice
newbe in VB.net.
Thanks,
|
|
|
|
|
I also had the experience that the designer support of it is really bad. You have to code this by hand. Hopefully this little example brings you on the right track:
Assuming you have a Menu Control named _menuMain:
MenuCommand topLevelCommand = new MenuCommand();
topLevelCommand.Text = "Top1";
_menuMain.MenuCommands.Add(topLevelCommand);
MenuCommand subLevelCommand1 = new MenuCommand();
subLevelCommand1.Text = "Sub1";
subLevelCommand1.Click += new EventHandler(subLevelCommand1_Click);
topLevelCommand.MenuCommands.Add(subLevelCommand1);
MenuCommand subLevelCommand2 = new MenuCommand();
subLevelCommand2.Text = "Sub2";
subLevelCommand2.Click += new EventHandler(subLevelCommand2_Click);
topLevelCommand.MenuCommands.Add(subLevelCommand2);
Surely you can set some more properties on every MenuCommand like Image (or ImageList and ImageIndex) or Shortcut. To add colors use the Extra... properties of the MenuCommands property.
You should also consider binding the Click events to a single method which then decides which operation to do:
public void MenuCommand_Click(object sender, EventArgs e){
if (sender == subLevelCommand1) {
} else if (sender == subLevelCommand2) {
}
}
-- modified at 12:46 Monday 16th January, 2006
I just noticed I've written the example in C#. Are you able to translate it yourself? If not I'll repost a VB.Net version
|
|
|
|
|
Let me try to convert to VB.net. I'll let you know.
Thanks
|
|
|
|
|
Thank you Robert!!
I tried but I don't think I have this correct. Please give me some advise:
Imports Crownwood.Magic.Menus<br />
Imports Crownwood.Magic.Common<br />
Imports Crownwood.Magic.Controls<br />
<br />
Public Class Form1<br />
Inherits System.Windows.Forms.Form<br />
<br />
#Region " Windows Form Designer generated code "<br />
<br />
Public Sub New()<br />
MyBase.New()<br />
<br />
'This call is required by the Windows Form Designer.<br />
InitializeComponent()<br />
<br />
'Add any initialization after the InitializeComponent() call<br />
<br />
End Sub<br />
<br />
'Form overrides dispose to clean up the component list.<br />
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)<br />
If disposing Then<br />
If Not (components Is Nothing) Then<br />
components.Dispose()<br />
End If<br />
End If<br />
MyBase.Dispose(disposing)<br />
End Sub<br />
<br />
'Required by the Windows Form Designer<br />
Private components As System.ComponentModel.IContainer<br />
<br />
'NOTE: The following procedure is required by the Windows Form Designer<br />
'It can be modified using the Windows Form Designer. <br />
'Do not modify it using the code editor.<br />
Friend WithEvents _menuMain As Crownwood.Magic.Menus.MenuControl<br />
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()<br />
Me._menuMain = New Crownwood.Magic.Menus.MenuControl<br />
Me.SuspendLayout()<br />
'<br />
'_menuMain<br />
'<br />
Me._menuMain.AnimateStyle = Crownwood.Magic.Menus.Animation.System<br />
Me._menuMain.AnimateTime = 100<br />
Me._menuMain.Cursor = System.Windows.Forms.Cursors.Arrow<br />
Me._menuMain.Direction = Crownwood.Magic.Common.Direction.Horizontal<br />
Me._menuMain.Dock = System.Windows.Forms.DockStyle.Top<br />
Me._menuMain.Font = New System.Drawing.Font("Tahoma", 11.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.World, CType(0, Byte))<br />
Me._menuMain.HighlightTextColor = System.Drawing.SystemColors.MenuText<br />
Me._menuMain.Location = New System.Drawing.Point(0, 0)<br />
Me._menuMain.Name = "_menuMain"<br />
Me._menuMain.Size = New System.Drawing.Size(292, 25)<br />
Me._menuMain.Style = Crownwood.Magic.Common.VisualStyle.IDE<br />
Me._menuMain.TabIndex = 0<br />
Me._menuMain.TabStop = False<br />
Me._menuMain.Text = "MenuControl1"<br />
'<br />
'Form1<br />
'<br />
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)<br />
Me.ClientSize = New System.Drawing.Size(292, 273)<br />
Me.Controls.Add(Me._menuMain)<br />
Me.Name = "Form1"<br />
Me.Text = "Form1"<br />
Me.ResumeLayout(False)<br />
<br />
End Sub<br />
<br />
#End Region<br />
<br />
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
AddMenu()<br />
End Sub<br />
<br />
Protected Sub AddMenu()<br />
Dim topLevelCommand = New MenuCommand<br />
<br />
topLevelCommand.Text = "File"<br />
_menuMain.MenuCommands.Add(topLevelCommand)<br />
<br />
Dim subLevelCommand1 = New MenuCommand subLevelCommand1.Text = "Exit"<br />
AddHandler subLevelCommand1.Click, AddressOf OnExitSelected<br />
topLevelCommand.MenuCommands.Add(subLevelCommand1)<br />
<br />
End Sub<br />
<br />
Public Sub OnExitSelected()<br />
<br />
End Sub<br />
<br />
End Class
I am getting an error in the MenuCommand of:
New MenuCommand
but I fixed this by adding the following Imports:
Imports Crownwood.Magic.Menus
Imports Crownwood.Magic.Common
Imports Crownwood.Magic.Controls
I am getting an error in the AddHandler .Click:
'Click' is not an event of 'System.Object'
I can't figure this one out.
|
|
|
|
|
You are very close
The problem comes from you variable definition:
Dim subLevelCommand1 = New MenuCommand
is implicitely translated by the compiler to this:
Dim subLevelCommand1 as Object
subLevelCommand1 = New MenuCommand
Thus you have an Object variable with just a MenuCommand as it contents, but the compiler isn't aware of that. Correct it should be:
Dim subLevelCommand1 as MenuCommand = New MenuCommand
Also the signature of the function OnExitSelected has to be changed:
Public Sub OnExitSelected(ByVal sender As Object, ByVal e As EventArgs)
Me.Close()
End Sub
Now everything should work fine
|
|
|
|
|
I would assume that this is also the way to add any control to the form programmatically:
Dim subLevelCommand1 as MenuCommand = New (type of control)MenuCommand
I came from the Alpha Micro world which was strictly ascii, no graphics. OOP is totally new to me. I do have a 1 foot stack of books on VB.NET but that is overwhelming. One step(or line) at a time.
Many Thanks!!!
|
|
|
|
|
No. Controls are added to a form this way:
Dim btn as Button = New Button
btn.Text = "Hello"
btn.Left = 10
btn.Top = 30
myForm.Controls.Add(btn)
|
|
|
|
|
I am writing some code in VB.NET which I parse a string to remove the domain name and back slash but the back slash remains in the TextBox. Here is the code.
Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\")
Dim myLength As Integer = Me.ebLoginName.TextLength()
If myStartPointer > 0 Then
Me.ebLoginName.Text() = Mid(Me.ebLoginName.Text(), _
myStartPointer + 2, myLength - myStartPointer + 1)
Me.mccDomain.Clear()
End If
Bob Zagars
Senior Software Engineer
|
|
|
|
|
Domain names have forward slashes in front of them, not back slashes. For example:
http://www.codeproject.com
|
|
|
|
|
Sorry for the wrong term been working long hours. Still should I re-post or can you answer my question?
Bob Zagars
Senior Software Engineer
-- modified at 14:47 Saturday 14th January, 2006
|
|
|
|
|
But in your code you are doing a string search for a back slash.
Dim myStartPointer As Integer = Me.ebLoginName.Text().IndexOf("\")
Or was this a typo too?
|
|
|
|
|
Then it is back slash.
A domain name is prefixed wih DOMANINAME\username.
When a user is defined with Windows Authentication it uses this format listed above. The original code was correct and works but does not remove the BACK SLASH.
If a user want Windows Authentication the domain name is necessary, otherwise it is the user name and a password has to be entered in another location on the form.
This is not a TYPO!
Bob Zagars
Senior Software Engineer
|
|
|
|
|
The issue is on line 3. If the first character in the string is a '\', which it likely will be with a path such as "\\Foo\Bar", then the index will be zero causing it to skip over your If condition.
You should change it to >= 0, like this...
If myStartPointer >= 0 Then
|
|
|
|
|
That would cause a problem if the back slash was at postion 0. This error happens even when the position is in the middle of the string.
Example MYDOMAINNAME\myusername
The results is from my code \myusername
If I add one to the start position of the Mid() method I will get \yusername
The code has nothing to do with the starting position it has to do with the removal of the back slash.
Bob Zagars
Senior Software Engineer
|
|
|
|