How to refresh win forms using vb.net? - vb.net

I am working for application register form and I would like to know when the user opens the register form I need to check if the current date is true or not and when the user tries to change the system date he should pop up message.So I would like to refresh the form for every second and find whether he has changed the date or not.
How do I do that?
Here is my code:
btnRegister.Enabled = False
Dim oReg As Microsoft.Win32.RegistryKey
oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
oReg = oReg.CreateSubKey(kstrRegSubKeyName)
oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\" & kstrRegSubKeyName)
Dim strOldDay As String = oReg.GetValue("UserSettings", "").ToString
Dim strOldMonth As String = oReg.GetValue("operatingsystem", "").ToString
Dim strOldYear As String = oReg.GetValue("GUID", "").ToString
Dim strRegName As String = oReg.GetValue("USERID", "").ToString
Dim strRegCode As String = oReg.GetValue("LOCALPATH", "").ToString
Dim strCompID As String = oReg.GetValue("CompID", "").ToString
Dim strTrialDone As String = oReg.GetValue("Enable", "").ToString
oReg.Close()
'If the keys should automatically be created, then create them.
If strOldDay = "" Then
CreateRegKeys(txtPassPhrase.Text)
End If
'If the keys are encrypted, decrypt them.
'If EncryptKeys = True Then
strOldDay = Decrypt(txtPassPhrase.Text, strOldDay)
strOldMonth = Decrypt(txtPassPhrase.Text, strOldMonth)
strOldYear = Decrypt(txtPassPhrase.Text, strOldYear)
'End If
'Define global variables.
mintUsedTrialDays = DiffDate(strOldDay, strOldMonth, strOldYear)
'Fill the progress bar
lblApplicationStatus.Text = DisplayApplicationStatus(DiffDate(strOldDay, strOldMonth, strOldYear), mintTrialPeriod)
'Disable the continue button if the trial is over
If DiffDate(strOldDay, strOldMonth, strOldYear) > mintTrialPeriod Then
'unregbutton.Enabled = False
mblnInTrial = False
btnRemind.Enabled = False
oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
oReg = oReg.CreateSubKey(kstrRegSubKeyName)
oReg.SetValue("Enable", "1")
oReg.Close()
End If
If strOldMonth = "" Then
Else
Dim dtmOldDate As Date = New Date(Convert.ToInt32(strOldYear), Convert.ToInt32(strOldMonth), Convert.ToInt32(strOldDay))
If Date.Compare(DateTime.Now, dtmOldDate) < 0 Then
'lblApplicationStatus.Text = DisplayApplicationStatus(mintTrialPeriod, mintTrialPeriod)
lblApplicationStatus.Text = "The system clock has been manually changed, and the application has been locked out to prevent unauthorized access!"
End If
End If
'If the trial is done then disable the button
If strTrialDone = "1" Then
mblnInTrial = False
btnRemind.Enabled = False
lblApplicationStatus.Text = "The system clock has been manually changed, and the application has been locked out to prevent unauthorized access!"
End If
'See if the user is already registered, if so re-process the info and check if the computer is all okay.,
If strRegName = "" Then
Else
Dim strRN As String = Decrypt(txtPassPhrase.Text, strRegName)
Dim strRC As String = Decrypt(txtPassPhrase.Text, strRegCode)
Dim UserName As String = strRegName
UserName = UserName.Remove(16, (UserName.Length - 16))
If UserName = Decrypt(txtPassPhrase.Text, strRegCode) Then
If Encrypt(txtPassPhrase.Text, cHardware.GetMotherBoardID.Trim.ToString) = strCompID Then
mblnInTrial = False
mblnFullVersion = True
strRC = strRC.Insert(4, "-")
strRC = strRC.Insert(8, "-")
strRC = strRC.Insert(12, "-") 'Add dashes to make it look cool
lblApplicationStatus.Text = "Licensed version to " + strRN + " with the key " + strRC
txtVKClientName.Enabled = False
txtKeyToValidate.Enabled = False
txtVKClientName.Text = strRN
txtKeyToValidate.Text = strRC
btnRemind.Text = "Registered"
frmMain.Text = "Aquamark v1.2(Registered)"
btnRegister.Hide()
Me.Close()
frmMain.Show()
oReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software", True)
oReg = oReg.CreateSubKey(kstrRegSubKeyName)
oReg.SetValue("Enable", "")
oReg.Close()
End If
End If
End If

NO, you don't have to "refresh the form for every second and find whether he has changed the date or not. How do I do that", the solution is a lot easier
The windows will send a message to all applications when the data is changed. Listen to that message instead and whenever the data changed do what you want to do so:
//C# sorry I don't know VB but the code is simple and you should convert it without any problem
private DateTime _lastSystemClockChanged = DateTime.MinValue;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x1E://the time is changed.
//to avoid receiving duplicate notification about time changed
if (_lastSystemClockChanged.AddSeconds(1) < DateTime.Now ||
_lastSystemClockChanged > DateTime.Now)
{
_lastSystemClockChanged = DateTime.Now;
//do what ever you want to do when time changed. note you should
//not call a methods that will block here because of you will block
//this message from arriving to other applications then
}
break;
}
base.WndProc(ref m);
}

You could subscribe to the SystemEvents.TimeChanged event, which is fired when the user changes the time on the system clock. Don't forget to detach the event handler when the form closes as this is a static event.
You could store a date in a field and compare the new date to it when the system time is changed, or just disable the app when the event occurs.

Related

Having problems with counter if i add an else in a nested if statement

if I try to put an else after exit while my counter doesn't work, I can find the first name but not the rest. I want to put the else to show a message box if the user has inputted a wrong name. i have tried putting else but if i search for eg the last name it doesn't work because the counter doesn't increments. please can you'll help me with the code without changing the loops.
Dim name(5) As String
Dim found As Boolean
Dim search As String
name(0) = "John"
name(1) = "Ken"
name(2) = "Jen"
name(3) = "Fam"
name(4) = "Denny"
search = InputBox("search name")
found = False
Dim counter As Integer = -1
While found = False
counter = counter + 1
If search = name(counter) Then
MsgBox("hello")
Exit While
End If
End While
End Sub
End Class
In this case I would recommend to use the For Each statement, since you are looping through a collection where you need the identifier. So instead of creating a seperate counter, just use the For Each identifier.
Dim name(4) As String
name(0) = "John"
name(1) = "Ken"
name(2) = "Jen"
name(3) = "Fam"
name(4) = "Denny"
Dim search = InputBox("search name")
Dim index As Integer = -1
For i = 0 To name.Length - 1
If name(i) = search Then
index = i
Exit For
End If
Next
If index > -1 Then
MsgBox("Name '" + name(index) + "' was found.")
Else
MsgBox("Name '" + search + "' was not found.")
End If
Just to give you an example I've removed the found boolean and used the found index (or object) instead. In case you want to lookup the object instead of just detecting if the name exists.
An alternative would be to use Linq (Imports System.Linq):
Dim found = name.Any(Function(n) n.Equals(search, StringComparison.InvariantCultureIgnoreCase))
You need to use th found boolean flag to tell you whether or not the name was found.You set it to true within the if statement and then check for its value after the loop ends. You also would need to exit the while loop after the counter reaches the last element in the list.
Dim name(5) As String
Dim found As Boolean
Dim search As String
name(0) = "John"
name(1) = "Ken"
name(2) = "Jen"
name(3) = "Fam"
name(4) = "Denny"
search = InputBox("search name")
found = False
Dim counter As Integer = -1
While found = False
counter = counter + 1
If search = name(counter) Then
MsgBox("hello")
found = True
Exit While
End If
If Counter = name.Length - 1
Exit While
End If
End While
If found = True Then
MsgBox("Name was found")
Else
MsgBox("Name was not found")
End If

Solidworks EPDM API IEdmEnumeratorVariable5::SetVar not working as expected

I'm trying to use IEdmEnumeratorVariable5::SetVar to update some file card variables based on user input into a windows form. My code executes, there are no error messages, the file is checked out and checked back in and the appropriate comment is added to the history; however the variables on the card are not updated.
I have verified by stepping through code at runtime that all variables are populated with the correct (as expected) data. The SetVar procedures all go off without a hitch, but the variables on the data card do not change value - even manually refreshing the folder view has no effect.
Below is my code.
This is an add-in application, written as a class-library project in VB using VS Community 2015, with target framework .NET 4.0.
In efforts to make this question more concise; immediately below I've included just the snippet of code doing the set variables work, then I've also included more code so you can get the whole picture if needed.
JUST THE TIP :
This is the code doing the set variables work:
Dim UserManager As IEdmUserMgr5 = .SourceVault
Dim User As IEdmUser5 = UserManager.GetLoggedInUser
CardComment = UserComment & CardComment
CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
CardBy = User.Name
CardDisposition = UserDisposition
CardVariables.SetVar(DispositionVariable, "#", CardDisposition)
CardVariables.SetVar(CommentVariable, "#", CardComment)
CardVariables.SetVar(ByVariable, "#", CardBy)
CardVariables.SetVar(DateVariable, "#", CardDate)
CardVariables.Flush()
THE BROADER STROKES :
Class module level variables:
Private Structure CommandInfo
Dim SourceVault As IEdmVault11
Dim SourceCommand As EdmCmd
Dim SourceSelection As System.Array
Dim TargetTemplate As System.String
Dim VerifiedPaths As List(Of String)
End Structure
Private ReceivedCommand As CommandInfo
OnCmd procedure (caller):
Public Sub OnCmd(ByRef poCmd As EdmCmd,
ByRef ppoData As System.Array) Implements IEdmAddIn5.OnCmd
Dim CommandToRun As MenuCommand
Try
With ReceivedCommand
.SourceVault = poCmd.mpoVault
.SourceCommand = poCmd
.SourceSelection = ppoData
'Get the command structure for the command ID
Select Case poCmd.meCmdType
Case EdmCmdType.EdmCmd_Menu
CommandToRun = AvailableCommands(.SourceCommand.mlCmdID)
Case EdmCmdType.EdmCmd_CardButton
Select Case True
Case poCmd.mbsComment.ToString.ToUpper.Contains("DISPOSITION")
DispositionRequest()
Case Else : Exit Sub
End Select
Case Else : Exit Sub
End Select
'...... (End Try, End Sub, Etc.)
DispositionRequest procedure (callee):
Private Sub DispositionRequest()
Dim UserDisposition As String
Using Disposition As New DispositionForm
With Disposition
If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
Select Case True
Case .Approve.Checked
UserDisposition = "Approved"
Case .Reject.Checked
UserDisposition = "Rejected"
Case Else : Exit Sub
End Select
End With
End Using
Dim UserComment As String
Using Explanation As New DispositionExplanation
With Explanation
If Not .ShowDialog() = System.Windows.Forms.DialogResult.OK Then Exit Sub
If .ListView1.Items.Count > 0 Then
'do some stuff not relevant to this question...
End If
UserComment = .Comments.Text
End With
End Using
'This next procedure just gets a list of paths from ReceivedCommand.SourceSelection - which is just the ppoData argument from the OnCmd procedure - see code block above!
Dim RequestPaths As List(Of String) = GetSelectedFilePaths()
For Each Path As String In RequestPaths
With ReceivedCommand
Dim RequestFile As IEdmFile5 = .SourceVault.GetFileFromPath(Path)
Dim ParentFolder As IEdmFolder6 = .SourceVault.GetFolderFromPath(System.IO.Path.GetDirectoryName(Path))
Dim UnlockLater As Boolean = False
If Not RequestFile.IsLocked Then
UnlockLater = True
RequestFile.LockFile(ParentFolder.ID, .SourceCommand.mlParentWnd, CInt(EdmLockFlag.EdmLock_Simple))
End If
Dim CardVariables As IEdmEnumeratorVariable5 = RequestFile.GetEnumeratorVariable
'We allow users to re-disposition a request so we want to keep any previous disposition information so it is not lost
Dim CardComment As String = String.Empty
Dim CardBy As String = String.Empty
Dim CardDate As String = String.Empty
Dim CardDisposition As String = String.Empty
Dim Success As Boolean
Const CommentVariable As String = "DispComm"
Const ByVariable As String = "DisposedBy"
Const DateVariable As String = "DisposedDate"
Const DispositionVariable As String = "Disposition"
Success = CardVariables.GetVar(DispositionVariable, "#", CardDisposition)
If Success Then
Success = CardVariables.GetVar(CommentVariable, "#", CardComment)
If Success Then Success = CardVariables.GetVar(ByVariable, "#", CardBy)
If Success Then Success = CardVariables.GetVar(DateVariable, "#", CardDate)
If Success Then CardComment = "Previously dispositioned as: """ & CardDisposition & """ by: " & CardBy & " on: " & CardDate & vbNewLine &
"---------Previous disposition explanation---------" & vbNewLine & CardComment
End If
Dim UserManager As IEdmUserMgr5 = .SourceVault
Dim User As IEdmUser5 = UserManager.GetLoggedInUser
CardComment = UserComment & CardComment
CardDate = Today().ToString("yyMMdd", Globalization.CultureInfo.InvariantCulture)
CardBy = User.Name
CardDisposition = UserDisposition
CardVariables.SetVar(DispositionVariable, "#", CardDisposition)
CardVariables.SetVar(CommentVariable, "#", CardComment)
CardVariables.SetVar(ByVariable, "#", CardBy)
CardVariables.SetVar(DateVariable, "#", CardDate)
CardVariables.Flush()
If UnlockLater Then RequestFile.UnlockFile(lParentWnd:= .SourceCommand.mlParentWnd,
bsComment:="Dispositioned as " & CardDisposition,
lEdmUnlockFlags:=0)
.SourceVault.RefreshFolder(ParentFolder.LocalPath)
End With
Next
End Sub
From the documentation:
bsCfgName : Name of configuration or layout to which to store the variable value; empty string for folders and file types that do not support configurations
I was working with a virtual file, which did not support configurations.
I saw a C example working with a virtual file and they were passing null references, so I reread the documentation and saw that excerpt above, so I changed my code from "#" to String.Empty for the mboconfiguration argument and now it is working!
CardVariables.SetVar(DispositionVariable, String.Empty, CardDisposition)
CardVariables.SetVar(CommentVariable, String.Empty, CardComment)
CardVariables.SetVar(ByVariable, String.Empty, CardBy)
CardVariables.SetVar(DateVariable, String.Empty, CardDate)
CardVariables.Flush()

Read and change combo-box selected item with 4 different possible values

I have a multi-line textbox that the user can type into; the contents of which are supposed to drive the currently selected item in a combobox.
I have existing code that works for two items currently (Yes & No); however, I now need to make this extend to supporting four items. This is also updated by a timer every 3 seconds, in case if the user manually updated the text. The combobox cannot be typed in, instead it has preset selections.
Also the program is designed to edit properties files.
I'm a little unsure on how to go about doing so.
This is what works for 2 item changes:
Dim lines as Textbox1.lines()
Dim ach_tr As String = "announce-player-achievements=" 'stuff to be replaced by string ach_ttr
Dim ach_ttr As String = "" 'empty string to delete string ach_tr
Dim ach As String = lines(My.Settings.AnnouncePlayerAchievements)'line of string ach_tr
ach = ach.Replace(ach_tr, ach_ttr)'removes string ach_tr and leaves the value
If ach = "true" Then
achievements.SelectedItem = "Yes"
Else
achievements.SelectedItem = "No"
End If
I've tried these for 4 items:
Dim lines as Textbox1.lines()
Dim diff_tr As String = "difficulty="
Dim diff_ttr As String = ""
Dim diff As String = lines(My.Settings.Difficulty)
diff = diff.Replace(diff_tr, diff_ttr)
If diff = "0" Then
achievements.SelectedItem = "Peaceful"
End If
If diff = "1" Then
achievements.SelectedItem = "Easy"
End If
If diff = "2" Then
achievements.SelectedItem = "Normal"
End If
If diff = "3" Then
achievements.SelectedItem = "Hard"
End If
And This one:
Dim lines as Textbox1.lines()
Dim diff_tr As String = "difficulty="
Dim diff_ttr As String = ""
Dim diff As String = lines(My.Settings.Difficulty)
diff = diff.Replace(diff_tr, diff_ttr)
If diff = "0" Then
achievements.SelectedItem = "Peaceful"
Else
If diff = "1" Then
achievements.SelectedItem = "Easy"
Else
If diff = "2" Then
achievements.SelectedItem = "Normal"
Else
If diff = "3" Then
achievements.SelectedItem = "Hard"
End If
End If
End If
End If
You could do something akin to:
var difficultyMap = new Dictionary<string,string>
{
{"0", "Peaceful"},
{"1", "Easy"},
{"2", "Normal"},
{"3", "Hard"}
};
difficultyCombo.Items = difficultyMap.Values;
updateTimer.Tick += (s,e) => {
var text = inputTextBox.Text;
string found;
if (!difficultyMap.TryGetValue(text))
{
MessageBox.Show("unknown difficulty");
return;
}
difficultyCombo.SelectedItem = found;
};
This is in C# as I don't know VB very well, but the core concepts should map, I'm also not sure of your exact implementation or requirements, in essence I've done the following:
Created a dictionary that goes from the "numeric" difficulty type to the display type for the combo
Populated the combo using the display values from the dictionary
Whenever the update timer fires, I:
Get the text from the textbox
Try to find the matching difficulty in the dictionary
Display an error or update the combo
Adding n number of items to the combo and text input is trivial now, as you just add a new entry to the dictionary.
Edit: For future reference Heres a more compact version which works as well:
Public LineNum As Globals.LineNumEnum
Dim serveriptr As String = ("server-ip=")
Dim sipc As String = PropView.OutputRTF.Lines(LineNum.SerIP)
sipc = sipc.Replace(serveriptr, Nothing)
I found my problem. I was trying to change the wrong combobox lol. well at least I learned about dictionaries and the select case. Well thanks for your time.
This is the correct code lol:
Dim diff_tr As String = "difficulty="
Dim diff_ttr As String = ""
Dim diff As String = lines(My.Settings.Difficulty)
diff = diff.Replace(diff_tr, diff_ttr)
If diff = "0" Then
difficulty.SelectedItem = "Easy"
ElseIf diff = "1" Then
difficulty.SelectedItem = "Easy"
ElseIf diff = "2" Then
difficulty.SelectedItem = "Normal"
ElseIf diff = "3" Then
difficulty.SelectedItem = "Hard"
End If

VB.Net Converting from string to double

I have a bad bug in my program where if a user presses the check(calculate) button when there is no input in the textbox the program displays this error: "Conversion from string "" to type 'Double' is not valid." I would like to resolve this but I am not sure how to do the conversion. I was thinking possibly CType but I am hearing talk of parsing. How do I go about this? the textbox is called mskTxtInput and the button object is called btnCheck which does all the calculation and processing.
Update: This is my code except the parsing method so hope this helps a little!
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
pic1.Visible = False 'hide picture
pic1.Image = My.Resources.A
pic2.Image = My.Resources.F
Dim value As Double
If Double.TryParse(mskTxtInput.Text, value) = Then
MsgBox("parsing success") ' parsing worked, so use the value in here
Else
MsgBox("parsing failed") ' parsing failed, so alert the user to that fact
End If
If radAdd.Checked = True Then
totalNum = num1 + num2
End If
If radSub.Checked = True Then
totalNum = num1 - num2
End If
If radMulti.Checked = True Then
totalNum = num1 * num2
End If
If mskTxtInput.Text = totalNum Then
lblAns.Text = ("Correct!")
lblAns2.Text = ("Answer is " & totalNum)
pic1.Visible = True
wins = wins + 1
nScore = wins
Else
lblAns.Text = ("Incorrect")
lblAns2.Text = ("Answer should be " & totalNum)
pic2.Visible = True
End If
attempts = attempts + 1
If attempts = 5 Then
MessageBox.Show("Game Finished! ", "End Of Game", _
MessageBoxButtons.OK, _
MessageBoxIcon.Exclamation)
lblAns.Text = ("You scored " & wins & " Out of 5")
btnSpin.Enabled = False
pic1.Visible = False
pic2.Visible = False
lblAns2.Text = ""
lblAns2.Text = "Play again?"
btnCheck.Enabled = False
btnNew.Enabled = True
attempts = 0
wins = 0
End If
mskTxtInput.Clear()
mskTxtInput.Focus()
End Sub
Try using Double.TryParse Method (String, Double) rather
Something like
Dim s As String
Dim result As Double
Dim returnValue As Boolean
returnValue = Double.TryParse(s, result)
Use the TryParse method to do the parsing to avoid getting an exception if the parsing fails:
Dim value As Double
If Double.TryParse(mskTxtInput.Text, value) Then
' parsing worked, so use the value in here
Else
' parsing failed, so alert the user to that fact
End If
dim iVar as integer
dim sStr as string
sstr=""
ivar = val(sstr)
Use the static method Double.TryParse(). If it returns true then parsing was successful, and you can proceed with the operation. If it returns false then parsing was not successful, and you should show an error message (using MessageBox if you desire) and abort the operation.

Problem with FedEx Address validation web service

I'm trying to get started with Fedex'es Address validation service and I'm running into a road block with FedEx's own demo application.
This is the code in there app:
Sub Main()
''# Build a AddressValidationRequest object
Dim request As AddressValidationRequest = New AddressValidationRequest()
Console.WriteLine("--- Setting Credentials ---")
request.WebAuthenticationDetail = New WebAuthenticationDetail()
request.WebAuthenticationDetail.UserCredential = New WebAuthenticationCredential()
request.WebAuthenticationDetail.UserCredential.Key = "###" ''# Replace "XXX" with the Key
request.WebAuthenticationDetail.UserCredential.Password = "###" ''# Replace "XXX" with the Password
Console.WriteLine("--- Setting Account Information ---")
request.ClientDetail = New ClientDetail()
request.ClientDetail.AccountNumber = "###" ''# Replace "XXX" with clients account number
request.ClientDetail.MeterNumber = "###" ''# Replace "XXX" with clients meter number
request.TransactionDetail = New TransactionDetail()
request.TransactionDetail.CustomerTransactionId = "Address Validation v2 Request using VB.NET Sample Code" ''# This is just an echo back
request.Version = New VersionId()
request.RequestTimestamp = DateTime.Now
Console.WriteLine("--- Setting Validation Options ---")
request.Options = New AddressValidationOptions()
request.Options.CheckResidentialStatus = True
request.Options.MaximumNumberOfMatches = 5
request.Options.StreetAccuracy = AddressValidationAccuracyType.LOOSE
request.Options.DirectionalAccuracy = AddressValidationAccuracyType.LOOSE
request.Options.CompanyNameAccuracy = AddressValidationAccuracyType.LOOSE
request.Options.ConvertToUpperCase = True
request.Options.RecognizeAlternateCityNames = True
request.Options.ReturnParsedElements = True
Console.WriteLine("--- Address 1 ---")
request.AddressesToValidate = New AddressToValidate(1) {New AddressToValidate(), New AddressToValidate()}
request.AddressesToValidate(0).AddressId = "WTC"
request.AddressesToValidate(0).Address = New Address()
request.AddressesToValidate(0).Address.StreetLines = New String(0) {"10 FedEx Parkway"}
request.AddressesToValidate(0).Address.PostalCode = "38017"
request.AddressesToValidate(0).CompanyName = "FedEx Services"
Console.WriteLine("--- Address 2 ---")
request.AddressesToValidate(1).AddressId = "Kinkos"
request.AddressesToValidate(1).Address = New Address()
request.AddressesToValidate(1).Address.StreetLines = New String(0) {"50 N Front St"}
request.AddressesToValidate(1).Address.PostalCode = "38103"
request.AddressesToValidate(1).CompanyName = "FedEx Kinkos"
Dim addressValidationService As AddressValidationService.AddressValidationService = New AddressValidationService.AddressValidationService
''#
Try
''# This is the call to the web service passing in a AddressValidationRequest and returning a AddressValidationReply
Console.WriteLine("--- Sending Request..... ---")
Dim reply As New AddressValidationReply()
reply = addressValidationService.addressValidation(request)
Console.WriteLine("--- Processing request.... ---")
''#This is where I get the error
If (Not reply.HighestSeverity = NotificationSeverityType.ERROR) And (Not reply.HighestSeverity = NotificationSeverityType.FAILURE) Then
If (Not reply.AddressResults Is Nothing) Then
For Each result As AddressValidationResult In reply.AddressResults
Console.WriteLine("Address Id - " + result.AddressId)
Console.WriteLine("--- Proposed Details ---")
If (Not result.ProposedAddressDetails Is Nothing) Then
For Each detail As ProposedAddressDetail In result.ProposedAddressDetails
Console.WriteLine("Score - " + detail.Score)
Console.WriteLine("Address - " + detail.Address.StreetLines(0))
Console.WriteLine(" " + detail.Address.StateOrProvinceCode + " " + detail.Address.PostalCode + " " + detail.Address.CountryCode)
Console.WriteLine("Changes -")
For Each change As AddressValidationChangeType In detail.Changes
Console.WriteLine(change.ToString())
Next
Console.WriteLine("")
Next
End If
Console.WriteLine("")
Next
End If
Else
For Each notification As Notification In reply.Notifications
Console.WriteLine(notification.Message)
Next
End If
Catch e As SoapException
Console.WriteLine(e.Detail.InnerText)
Catch e As Exception
Console.WriteLine(e.Message)
End Try
Console.WriteLine("Press any key to quit !")
Console.ReadKey()
End Sub
It seems to send the request object to the web service, but the"reply" object is returned with "Nothing". I could understand if I wrote the code, but good god... they can't even get their own code to work? Has anyone else seen/fixed this problem?
The app shows some tell-tale signs of having been first written in C# and then converted to VB.Net later. Specifically:
Dim request As AddressValidationRequest = New AddressValidationRequest()
Could be shortened to simply:
Dim request As New AddressValidationRequest()
.
If (Not reply.HighestSeverity = NotificationSeverityType.ERROR) And (Not reply.HighestSeverity = NotificationSeverityType.FAILURE) Then
could be written several ways, but at very least I would expect a pure-VB programmer to know of either AndAlso instead of And or <> instead of Not ... = .... Finally:
Dim reply As New AddressValidationReply()
reply = addressValidationService.addressValidation(request)
creates a new object and promptly discards it.