[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
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:
Option Explicit
Public Enum FTypes
Phone = 0
Mobile = 1
BirthDate = 2
End Enum
Public Function DataFormat(ByVal InData As String, ByVal FormatType As FTypes) As String
Select Case FormatType
Case Phone
' Do your phone stuff
Case Mobile
' Do your mobile phone stuff
Case BirthDate
' Do your birthdate stuff
Case Else
MsgBox "Invalid FormatType"
End Select
End Function
Private Sub Form_Load()
'
' Call the function like this
'
MsgBox DataFormat("10/7/2006", BirthDate)
End Sub
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:
Private Sub Text1_Change()
'---
Dim intPhone As Integer
'--- Formatting the Client phone number.
If Len(Text1.Text) = 14 Then
Else
If intPhone = 1 Then
If Len(Text1.Text) = 10 Then
Text1.Text = [COLOR=Red]DataFormat[/COLOR](ByVal Text1.Text, Phone)
End If
End If
End If
intPhone = 1
End Sub
Thanks aktell
Re: Managing Complexity of Code in a One Form Application.
Why you got a byval in there ?
VB Code:
Text1.Text = DataFormat(Text1.Text, Phone)
1 Attachment(s)
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
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 ?
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
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:
Public Function DataFormat(ByVal InData As String, ByVal FormatType As FTypes) As String
'---
'--- Before these where just (str_One, str_Two, str_Three) as they where in separate Public Functions.
Dim str_One As String
Dim str_Two As String
Dim str_Three As String
Select Case FormatType
Case Phone
str_One = Mid(InData, 1, 2)
str_Two = Mid(InData, 3, 4)
str_Three = Mid(InData, 7, 4)
DataFormat = "(" & str_One & ") " & str_Two & "-" & str_Three
Case Mobile
str_One = Mid(InData, 1, 4)
str_Two = Mid(InData, 5, 3)
str_Three = Mid(InData, 8, 3)
DataFormat = "(" & str_One & ") " & str_Two & "-" & str_Three
Case BirthDate
str_One = Mid(InData, 1, 2)
str_Two = Mid(InData, 3, 2)
str_Three = Mid(InData, 5, 4)
DataFormat = str_One & "/" & str_Two & "/" & str_Three
' Case Else
End Select
End Function
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 :wave: