Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual Basic 2010

Options
  • 09-12-2012 3:12pm
    #1
    Registered Users Posts: 17


    Hi Everyone

    I'm currently doing a course in Visual Basic 2010 (distant learning) and I'm struggling. I got 3 exams in the coming months starting late January, one in March and one in May. I have or will have past papers to prepare me. Ideally what I'm after is someone to go over each paper with me when I get it and check my work. I'm in Gorey. Anyone out there able to do this? and what would be the cost. I guess I'm looking for some one on one tutoring. Other than that any good links or forum suggestions of where to look for tips.

    thanks


Comments

  • Moderators, Technology & Internet Moderators Posts: 11,015 Mod ✭✭✭✭yoyo




  • Registered Users Posts: 419 ✭✭Mort5000


    With what are you struggling?

    If I were you, I'd post my questions here when you have them, and see how it goes from there.
    You may not need any in-person assistance.


  • Registered Users Posts: 17 hir303


    I suppose I'll give it a go. I'll dig out something later on.

    thanks


  • Registered Users Posts: 17 hir303


    Hi all

    I'm looking for code to remove all no letter characters for a string in vb 2010.
    Anyone any ideas?

    thanks


  • Registered Users Posts: 607 ✭✭✭brianwalshcork


    I guess you mean "non letter" characters?

    I.e. If you have the following string:

    Abc123def$&@gh

    Then you want to end up with:

    Abcdefgh

    To do this, you'll need. FOR loop, inside the loop check whether the character is a letter if it is, add it to a result string, if not, do nothing.
    I'm not a VB guy, so don't know the exact function for checking whether a character is a letter or not, but in other languages, I'd get the ASCII value and see I'd it falls within the range of letter values.

    Brian


  • Advertisement
  • Registered Users Posts: 38 kmc25_1


    Don't know visual basic at all.....

    but I know how to use google search :):

    http://www.freevbcode.com/ShowCode.asp?ID=8572


  • Registered Users Posts: 17 hir303


    Thanks Brian

    Having a look at For Loop ath the moment.

    thanks


  • Registered Users Posts: 17 hir303


    Thanks kmc21 1

    So do I, but unfortuntly I can't find the exact match for my answer. Think it's a combination of For - If - Else.


  • Registered Users Posts: 607 ✭✭✭brianwalshcork


    The code linked by Kmc is the opposite of what (i think) you need, but the techniques required are the same, so it's not a bad starting point.


  • Closed Accounts Posts: 22,479 ✭✭✭✭philologos


    Look up Regex.Replace. The syntax in VB should be similar to C#. Looping through the whole result set is excessive.


  • Advertisement
  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    philologos wrote: »
    Look up Regex.Replace. The syntax in VB should be similar to C#. Looping through the whole result set is excessive.

    Now you've just given him 2 problems :D


  • Registered Users Posts: 851 ✭✭✭TonyStark


    hir303 wrote: »
    Hi all

    I'm looking for code to remove all no letter characters for a string in vb 2010.
    Anyone any ideas?

    thanks

    It's in C# but you should get the idea:
            static void Main(string[] args)
            {
                const string input = "Abc123def$&@gh";
    
                // for loop
                string output = string.Empty;
    
                for (int i = 0; i < input.Length; i++)
                {
                    var letter = char.Parse(string.Format("{0}", input[i]).ToLower());
    
                    if ((letter <= 'z' && letter >= 'a'))
                    {
                        output = output + input[i];
                    }
                }
    
                Console.WriteLine("For Loop:");
                Console.WriteLine(output);
                
    
                // using regex
                output = Regex.Replace(input, "[^A-Za-z]", "");
    
                Console.WriteLine("Regular Expression:");
                Console.WriteLine(output);
    
                Console.ReadKey();
            }
    


  • Registered Users Posts: 17 hir303


    Thanks

    Looks a bit like what I'm trying alright. Thanks


  • Registered Users Posts: 2,781 ✭✭✭amen


    Look up Regex.Replace. The syntax in VB should be similar to C#. Looping through the whole result set is excessive.

    Agreed but the point of the exercise is to learn how to program.

    hir303 before writing any code think about the problem and describe in english how you would solve the problem (pseudocode).

    So for you example it migh be
    Get a string
    Get the number of characters in the string
    FOR each character in the string
    IF the character is a letter write it to a new string
    Once all of the characters have been checked set the old string equal to the new string


  • Registered Users Posts: 17 hir303


    Hi amen.

    I get your point on the design code. The problem I have is in coding the for loop.

    Method Changethestring(input As String) As String
    ’Preconditions: none
    ’Postconditions: A string is returned that consists of all the letter
    ’characters from input in the same order and with the same
    ’multiplicity, but in lower case. For example, if input is
    ’"Happy Birthday!", then "happybirthday" is returned.
    result As String
    temp As Char
    Set result To ""
    For i As Integer From 0 To ’Add expression here. (input.Length Step 1)
    ’Give the loop body here so that the For loop will add all the letter characters in input to result.
    End For
    ’Add a line of code to convert result to lower case here. (result = input.ToLower)
    Return result
    EndMethod


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    amen wrote: »
    Agreed but the point of the exercise is to learn how to program.

    hir303 before writing any code think about the problem and describe in english how you would solve the problem (pseudocode).

    So for you example it migh be
    Get a string
    Get the number of characters in the string
    FOR each character in the string
    IF the character is a letter write it to a new string
    Once all of the characters have been checked set the old string equal to the new string

    Plus 1 to that. At this stage you need to write out the logic behind what you are doing before you even think about how you will write the code for it. Its gets you thinking along the right lines and you generally have all the logic down pat before you write a line of code. I've been writing code professionally for 20 years (19 of those in some variant of VB or C) and i still do this. Also, breaking it down this way makes the problem seem less complicated.

    On another note (and not a dig at anybody on this thread) but just giving somebody at this stage of learning programming a lump of code and telling them that it solves their problem isnt always the most constructive. People generally dont learn very well that way. They need to be shown how to approach the problem not just given the answer.


  • Registered Users Posts: 851 ✭✭✭TonyStark


    Beano wrote: »
    Plus 1 to that. At this stage you need to write out the logic behind what you are doing before you even think about how you will write the code for it. Its gets you thinking along the right lines and you generally have all the logic down pat before you write a line of code. I've been writing code professionally for 20 years (19 of those in some variant of VB or C) and i still do this. Also, breaking it down this way makes the problem seem less complicated.

    On another note (and not a dig at anybody on this thread) but just giving somebody at this stage of learning programming a lump of code and telling them that it solves their problem isnt always the most constructive. People generally dont learn very well that way. They need to be shown how to approach the problem not just given the answer.


    When I was learning I found a lot of people tend to shy away from providing a concrete example and give a more generalized answer which can leave people as bewildered as when they started and in some cases make them reluctant to ask more questions.

    I don't condone people doing people's homework for them, but I do think it can be helpful from time to time to provide something more concrete that people can examine, step through and learn from.


  • Closed Accounts Posts: 22,479 ✭✭✭✭philologos


    I don't think that pointing people to a useful API in the .NET framework is a bad idea by the by. Looking to the API reference in C# is abundantly useful for knowing what tools are at your disposal.


  • Registered Users Posts: 851 ✭✭✭TonyStark


    hir303 wrote: »
    Hi amen.

    I get your point on the design code. The problem I have is in coding the for loop.

    Method Changethestring(input As String) As String
    ’Preconditions: none
    ’Postconditions: A string is returned that consists of all the letter
    ’characters from input in the same order and with the same
    ’multiplicity, but in lower case. For example, if input is
    ’"Happy Birthday!", then "happybirthday" is returned.
    result As String
    temp As Char
    Set result To ""
    For i As Integer From 0 To ’Add expression here. (input.Length Step 1)
    ’Give the loop body here so that the For loop will add all the letter characters in input to result.
    End For
    ’Add a line of code to convert result to lower case here. (result = input.ToLower)
    Return result
    EndMethod


    Convert the input string to an array.

    Loop through the array, bear in mind that if a string is of length 7 then the index of the first letter will be 0 and the index of the last letter will be 6 So make sure that when you do loop you take this into account.

    With each character that you loop through you need to check that it fulfills the condition ie. is it a letter? If it is, then you add it to the new string otherwise you just ignore it.

    You can probably call the toLower() function on each iteration of the loop or you could just leave it to the very end. In this case it probably doesn't matter so much but when the inputs get more unwieldy it may give you a small performance gain.


  • Registered Users Posts: 17 hir303


    Thanks All

    So far I have this running in a console and have a watcher running on some of the parts.
    The loop runns through the indexes.
    Next bit for me now is to get the contents at the index to add to the result string.

    Dim result As String
    Dim input As String
    Dim temp As Char
    result = ""
    input = "Happy Birthday!"

    For i As Integer = 0 To input.Length - 1 Step 1
    If Char.IsLetter(input(i)) Then
    ??????
    End If
    Next

    result = input.ToLower
    Console.WriteLine(result)


  • Advertisement
  • Registered Users Posts: 851 ✭✭✭TonyStark


    hir303 wrote: »
    Thanks All

    So far I have this running in a console and have a watcher running on some of the parts.
    The loop runns through the indexes.
    Next bit for me now is to get the contents at the index to add to the result string.

    Dim result As String
    Dim input As String
    Dim temp As Char
    result = ""
    input = "Happy Birthday!"

    For i As Integer = 0 To input.Length - 1 Step 1
    If Char.IsLetter(input(i)) Then
    ??????
    End If
    Next

    result = input.ToLower
    Console.WriteLine(result)


    You need to build your output string. So if the result of the If returns true you want to add the letter to the new string, in other words you want to append the letter to your new string for each time the if fires.

    That way if the if doesn't fire, it means you will skip anything that isnt a letter.

    So your result will be set to the current value of result + [The next letter from input that satisfies the condition]


  • Registered Users Posts: 17 hir303


    Thanks for all the comments

    Figured it out in the end:

    Dim result As String
    Dim input As String
    result = ""
    input = "Happy Birthday!"

    For i As Integer = 0 To input.Length - 1 Step 1
    If Char.IsLetter(input(i)) Then
    Convert.ToString(input(i))
    result = result + input(i)
    End If
    Next
    result = result.ToLower
    Console.WriteLine(result)


    I'm still looking for a tutor to go over some old papers to prepare me for and exam. I'm in Gorey but can travel.


  • Closed Accounts Posts: 3,357 ✭✭✭Beano


    hir303 wrote: »
    Thanks for all the comments

    Figured it out in the end:

    Dim result As String
    Dim input As String
    result = ""
    input = "Happy Birthday!"

    For i As Integer = 0 To input.Length - 1 Step 1
    If Char.IsLetter(input(i)) Then
    Convert.ToString(input(i))
    result = result + input(i)
    End If
    Next
    result = result.ToLower
    Console.WriteLine(result)


    I'm still looking for a tutor to go over some old papers to prepare me for and exam. I'm in Gorey but can travel.

    Seems ok but the line

    Convert.ToString(input(i))

    Does nothing and you dont need it.


  • Registered Users Posts: 17 hir303


    Thanks Beano

    thats from an earlier attempt, forgot to remove it.


Advertisement