Results 1 to 9 of 9

Thread: [RESOLVED] Managing Complexity of Code in a One Form Application.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Resolved [RESOLVED] Managing Complexity of Code in a One Form Application.

    Hi there,

    I’m still trying to get on top of my code or say better of the vast amount of it. My question this time is towards Public Functions which I would like to consolidate.

    Meaning:That I have several Public Functions i.e. PhoneFormat, MobilePhoneFormat, BirthDateFormat etc. etc. which I would like to combine within ONE Public Funtion in a module maybe using a Select Case statements, calling the same as before.
    Now my question is: Is this possible ???

    Thanks aktell

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Managing Complexity of Code in a One Form Application.

    It's just a matter of passing the expected format type to the function, something like this...
    VB Code:
    1. Option Explicit
    2.  
    3. Public Enum FTypes
    4.     Phone = 0
    5.     Mobile = 1
    6.     BirthDate = 2
    7. End Enum
    8.  
    9. Public Function DataFormat(ByVal InData As String, ByVal FormatType As FTypes) As String
    10.  
    11.     Select Case FormatType
    12.         Case Phone
    13.             ' Do your phone stuff
    14.         Case Mobile
    15.             ' Do your mobile phone stuff
    16.         Case BirthDate
    17.             ' Do your birthdate stuff
    18.         Case Else
    19.             MsgBox "Invalid FormatType"
    20.     End Select
    21.    
    22. End Function
    23.  
    24. Private Sub Form_Load()
    25.     '
    26.     ' Call the function like this
    27.     '
    28.     MsgBox DataFormat("10/7/2006", BirthDate)
    29.    
    30. End Sub
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Re: Managing Complexity of Code in a One Form Application.

    Hi there,

    Well, so far so good. But I can't get it to work at this stage.

    Err. Message "Argument not optional" it just highlights in the code the DataFormat.
    VB Code:
    1. Private Sub Text1_Change()
    2. '---
    3.  Dim intPhone As Integer
    4.  
    5. '--- Formatting the Client phone number.
    6.             If Len(Text1.Text) = 14 Then
    7.             Else
    8.                 If intPhone = 1 Then
    9.                   If Len(Text1.Text) = 10 Then
    10.                        Text1.Text = [COLOR=Red]DataFormat[/COLOR](ByVal Text1.Text, Phone)
    11.                   End If
    12.                 End If
    13.             End If
    14.             intPhone = 1
    15. End Sub

    Thanks aktell

  4. #4
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Managing Complexity of Code in a One Form Application.

    Why you got a byval in there ?

    VB Code:
    1. Text1.Text = DataFormat(Text1.Text, Phone)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Re: Managing Complexity of Code in a One Form Application.

    Hi there,

    Well, I have been trying as much as, but seem not to get ahead with this one. So it's out again to find some HELP.
    Below I have attached a Zip file as simple as.. I know it's not pretty but I'm trying.

    Any help would be greatly appriciated.

    Thanks aktell
    Attached Files Attached Files

  6. #6
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Managing Complexity of Code in a One Form Application.

    What help do you require? People tend not to want to recode an entire project for someone, ask specific questions and you will get specific answers.

    Did the first question not work ?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Re: Managing Complexity of Code in a One Form Application.

    Quote Originally Posted by Grimfort
    What help do you require? People tend not to want to recode an entire project for someone, ask specific questions and you will get specific answers.

    Did the first question not work ?
    Hithere,

    I can't say that I was NOT asking for a recode. I have gone by the first sugestion from "pnish" and set the little project up not using or trying it in my code before I was sure it would work. I also use your sugestion in not using ByVal fine. Now I'm showing you the code which I would like to use as is IF IT WOULD WORK.
    I have been asking the last few days only some questions to get away from the vast amount in my project, but not to change my project with anybody's help but to reduce MY code. I have ask if it would be possible to do but not to rewrite or even to write any code for me, so it seems that your responce is not really fair at all. And by the way WE CAN"T BE ALL GURUS, but then some of them here on this site are GURUS with character, some of them with alot some of them with a little or none.

    So if you one of the first THANKS IN ADVANCE if not well, thanks anyway.

    aktell

  8. #8
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Managing Complexity of Code in a One Form Application.

    Your correct, maybe my post was not fair. I have only read this one post from you so can not see your history, but it did sound like a "heres my project, it doesnt work" post. So I apoligise *me bows*.

    VB Code:
    1. Public Function DataFormat(ByVal InData As String, ByVal FormatType As FTypes) As String
    2. '---
    3. '--- Before these where just (str_One, str_Two, str_Three) as they where in separate Public Functions.
    4.     Dim str_One As String
    5.     Dim str_Two As String
    6.     Dim str_Three As String
    7.  
    8.     Select Case FormatType
    9.         Case Phone
    10.             str_One = Mid(InData, 1, 2)
    11.             str_Two = Mid(InData, 3, 4)
    12.             str_Three = Mid(InData, 7, 4)
    13.             DataFormat = "(" & str_One & ") " & str_Two & "-" & str_Three
    14.        
    15.         Case Mobile
    16.             str_One = Mid(InData, 1, 4)
    17.             str_Two = Mid(InData, 5, 3)
    18.             str_Three = Mid(InData, 8, 3)
    19.             DataFormat = "(" & str_One & ") " & str_Two & "-" & str_Three
    20.            
    21.         Case BirthDate
    22.             str_One = Mid(InData, 1, 2)
    23.             str_Two = Mid(InData, 3, 2)
    24.             str_Three = Mid(InData, 5, 4)
    25.             DataFormat = str_One & "/" & str_Two & "/" & str_Three
    26.            
    27. '        Case Else
    28.  
    29.     End Select
    30.    
    31. End Function
    Last edited by Grimfort; Jul 11th, 2006 at 06:04 AM.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Location
    Germany, New Zealand, now in Australia
    Posts
    143

    Re: [RESOLVED] Managing Complexity of Code in a One Form Application.

    Hi there,

    Well, YES it works perfectly fine so thanks alot. One done and one more to go so maybe I have the pleasure to talk to YOU: pnish or Grimfort Again.

    Thanks aktell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width