|
-
Apr 15th, 2011, 10:31 PM
#1
Thread Starter
Fanatic Member
Passing multiple String.Format()
I was fed up of having a duplicate method side by side so merged them into one. Both sent a request to another class.
vb Code:
Private _messageFormats() As String = { _
String.Format(RegistrySettings.PMessageData, Identity, Topic, Body, RegistrySettings.ServerCookieToken), _
String.Format(RegistrySettings.ThreadData, Topic, Body, RegistrySettings.ServerCookieToken)}
The issue comes because Identity, topic, body are all member variables declared at run time. and when sending the string.format to another method, Them three ate null since they are already set
any solutions?
-
Apr 16th, 2011, 02:30 AM
#2
Re: Passing multiple String.Format()
You need to pass those values to wherever that code is, as method parameters.
-
Apr 16th, 2011, 03:14 AM
#3
Thread Starter
Fanatic Member
Re: Passing multiple String.Format()
Thats the trouble i was facing john. I had two identical methods that passed the same string except one contained 4 elements and the other 3 elements.
So i was wondering if there was a way to hard code both string.format lines and pass when needed. Do you have any alternative suggestions?
-
Apr 16th, 2011, 03:45 AM
#4
Re: Passing multiple String.Format()
I'm afraid that I don't really understand what you're asking for. Perhaps you should show us exactly what you've got and explain exactly what's wrong with it.
-
Apr 16th, 2011, 04:14 AM
#5
Thread Starter
Fanatic Member
Re: Passing multiple String.Format()
Ok sorry.
Right i am using httpwebrequest to login to my server. This class is called ConnectionManager.
Along side the login method that class contains another method that creates a Httprequest for Two different tasks depending on what information is passed.
This information is sent from userControl1 for arguments sake. Before i use to call this class i would use select case to determine True on Two radio buttons.
Rad 1 - passes a string using string format containing 4 elements
Rad 2 - passes a string using string format containing 3 elements
I would call from usercontrol1 Either method1 or method2 depending on what rad button was checked then both done identical settings other then the string.format part. Then passed the information on to the class
Now i hate duplicate code so wanted to try merge them into one..
SF1 :
vb Code:
String.Format(RegistrySettings.PMessageData, Identity, Topic, Body, RegistrySettings.ServerCookieToken)
SF2 :
vb Code:
String.Format(RegistrySettings.ThreadData, Topic, Body, RegistrySettings.ServerCookieToken)
My first post i tried to save them as member variables but obviously they would return null.
I just want a more functional way to pass these two string.formats rather then having duplicate code.
Merge these two
vb Code:
Private Sub HandleComposeMessageConnection(ByVal topic As String, ByVal body As String)
_connectionManager.HandleRequestedUrl = ComposeMessageUrl
_connectionManager.HandleRequestedData = String.Format(RegistrySettings.PMessageData, _
txtPostIdentityNumber.Text, _
topic, _
body, _
RegistrySettings.ServerCookieToken)
_connectionManager.InitiateMessage()
End Sub
Private Sub HandleComposeThreadConnection(ByVal topic As String, ByVal body As String)
_connectionManager.HandleRequestedUrl = ComposeThreadUrl & txtPostIdentityNumber.Text
_connectionManager.HandleRequestedData = String.Format(RegistrySettings.ThreadData, _
topic, _
body, _
RegistrySettings.ServerCookieToken)
_connectionManager.InitiateMessage()
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|