"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused
"constfixed" VERY Confused "constfixed" VERY Confused
"constfixed" VERY Confused
Go Back  Xtreme Visual Basic Talk > > > "constfixed" VERY Confused


Reply
 
Thread Tools Display Modes
  #1  
Old 10-03-2005, 09:58 AM
Timberly Timberly is offline
Newcomer
 
Join Date: Sep 2005
Posts: 9
Default "constfixed" VERY Confused


I'm sorry to ask for help, I don't want to waste any of your time but I'm very thankful to anyone who can help!

I'm a 16yr old doing a Computign course, now as part of it I've been given a worksheet with the following code, I'm supposed to type this in and try it on it's own:

Code:
Dim Place As Integer Dim Place1 As Integer Dim Sample As String Dim length As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load constfixed = "John Paul Jones" Place = InStr(constfixed, "") Place1 = InStrRev(constfixed, "") length = Len(constfixed) Sample = constfixed.Substring(0, Place) MsgBox(Sample) End Sub

But this doesn't do anything, and Constfixed is underlined in Blue. Our worksheets were made for VB 6.0, which I suspect to be the problem. Am I correct? And do you know the correct code to use?

Any help will be much appreciated, it's important and I'm clueless. I searched the help but it didn't display any matches for "constfixed", Thanks even for reading this.

[EDIT: Oh bother, now I've posted it in the wrong section, it's meant to be in the .NET section, truly sorry. Nothing seems to be going how it should today.]
Reply With Quote
  #2  
Old 10-03-2005, 10:05 AM
OnErr0r's Avatar
OnErr0r"constfixed" VERY Confused OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

constfixed should be in a string variable or constant too. IndexOf and LastIndexOf would be more appropriate in .net than Instr and InstrRev. And MessageBox instead of MsgBox.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #3  
Old 10-03-2005, 10:07 AM
John's Avatar
John John is offline
Bit Flipper
 
Join Date: Feb 2002
Location: The Inner Loop
Posts: 5,550
Default

Yes, VB6 is the problem because by default in VB6 you didn't have to declare your variables while in VB.NET you do (by default). You can fix this by declaring the variable "constfixed" with the others like so:
Code:
'... Dim Place As Integer Dim Place1 As Integer Dim Sample As String Dim constfixed As String Dim length As Integer '...

It sounds from the name of the variable that it should be a constant though. In that case you would do it like so:
Code:
'... Dim Place As Integer Dim Place1 As Integer Dim Sample As String Const constfixed = "John Paul Jones" Dim length As Integer '...
Then you would remove the assignment in the Form_Load since you can't assign to a constant after it is created.
Edit by John: To add to what OnErr0r was saying, you can also use constfixed.Length() instead of Len(constfixed).
__________________
Subclassing|Magnetic Forms|Operator Overloading (VB2K5)|QuickSnip.NET

"These Patriot playoff wins are like Ray Charles songs, Nantucket sunsets, and hot fudge sundaes. Each one is better than the last." - Dan Shaughnessy
Reply With Quote
  #4  
Old 10-03-2005, 10:13 AM
Timberly Timberly is offline
Newcomer
 
Join Date: Sep 2005
Posts: 9
Default

Aha! A curse on my schools outdated worksheets.

Thank you John, and you OnErr0R, very very much. =D
Reply With Quote
  #5  
Old 10-03-2005, 11:41 AM
Timberly Timberly is offline
Newcomer
 
Join Date: Sep 2005
Posts: 9
Default

*Sigh*

Alas, I have struck another stumbling block. You see what this is building up to is a very simple translation program. Right now I'm just using this code to get at least to be able to split the sentence the user enters into individual words.

But I do not know how best to split the middle words, here is my current code:

Code:
Dim Place1 As Integer 'Place1 is the number of the first blank character in the sentence Dim Place2 As Integer 'Place2 is the number of the last blank character in the sentence Dim constfixed As String Dim length As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Sentence, FirstWord, LastWord, MidWords As String constfixed = TextBox1.Text Place1 = InStr(constfixed, " ") Place2 = InStrRev(constfixed, " ") length = Len(constfixed) Sentence = constfixed ' Creates text string. FirstWord = Mid(Sentence, 1, Place1) ' Returns the first word. MidWords = Mid(Sentence, Place1 + 1, Place2 - Place1) ' Returns everything between the first and last words. LastWord = Mid(Sentence, Place2 + 1, length) ' Returns the last word. MsgBox(FirstWord) MsgBox(MidWords) MsgBox(LastWord) End Sub

You see the program splits the sentence you enter and dispalys each word n a Message Box, however I'd like to know how to split the "MidWords" into separate words.
I know I haven't updated the code as John and OnErr0r said, but I woud like to. It's just I'd like to get it working using the method described by my teacher before I update it. If it helps I can upload the project files.
Reply With Quote
  #6  
Old 10-03-2005, 01:42 PM
OnErr0r's Avatar
OnErr0r"constfixed" VERY Confused OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

You might consider using String.Split on " " instead. That will return an array of the words. If necessary you can add more code to handle punctuation.

Edit: 10K woot!
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #7  
Old 10-03-2005, 01:53 PM
Timberly Timberly is offline
Newcomer
 
Join Date: Sep 2005
Posts: 9
Default

hehe thanks OnErr0r, and congratulatiosn on the 10,000 post!

But I just finished the translator program, I thought about it, and after combing MSDN I found "replace". So now I'm using Replace and for a translator program it's perfect.

Last edited by Timberly; 10-03-2005 at 03:30 PM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused "constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused "constfixed" VERY Confused
"constfixed" VERY Confused
"constfixed" VERY Confused
 
"constfixed" VERY Confused
"constfixed" VERY Confused
 
-->