Wrox Programmer Forums
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 15th, 2012, 04:01 PM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Testing for blanks strings

1- In the projects Propertie's 'Settings' I have a name 'MyNote' of type String'
and scope 'User'.

2- In a form there is a textbox1 and a button named 'Save'.

3- when the button is clicked the following code is executed:
my.settings.mynote = textbox1.text

4- Why doesn't the following code work:
dim t as string
t = trim(my.settings.mynote)
if t = "" then
msgbox("Please enter something")
end if

5- the msg is always displayed, even when textbox1.text = "" I noticed that the length of my.settings.mynote = 1024 when all is blank. I tried using NullOrNothing and Nothing. Still same results. What is the trick to test if blank?

Last edited by toconce; November 15th, 2012 at 04:07 PM..
 
Old November 16th, 2012, 06:25 AM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

A Few things here:-

1) You quote "the msg is always displayed, even when textbox1.text = ""
". If the TextBox.Text is empty and then you click your save Button then it will always show the message since you use:-

Code:
Dim t As String
t = Trim(My.Settings.MyNote)

If t = "" Then
  MsgBox("Please enter something")
End If
2) You quote "I noticed that the length of my.settings.mynote = 1024 when all is blank." What you need to remember is that the Project Setting Value field for each setting is the Default Value applied if you have not set the value elsewhere. In your case I guess that you have not set a default value, therefore it is blank, and applying a setting to your value in code does NOT change the default value in the settings tab.

3) You quote "I tried using NullOrNothing and Nothing. Still same results. What is the trick to test if blank?" The best way to check for an empty string is to use String.Empty. Try these two examples:-

Code:
If t = String.Empty Then
  MsgBox("Empty")
Else
  MsgBox(t)
End If

If Not t = String.Empty Then
  MsgBox(t)
Else
  MsgBox("Empty")
End If
Hope that helps.

Cheers,

Ian
 
Old November 16th, 2012, 11:46 AM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ian, thanks for the reply. I have tried your code plus my.settings.mynote ="", my.settings.mynote =" ", and my.settings.mynote =Nothing. Still does not work. I forgot to mention that the testing for blank is done when the form is loaded at startup; not while the project is running; also I'm using VB 2010 Express (the free copy). I'm convinced that there is a non printable character there because when testing the results, instead of showing "" it shows " " but the width of the blank is half the size (I have searched the entire project for code that might be storing into my.settings.mynote).
Anyhow, I need to continue onwards, so for the time being I'm setting it to "none" and testing for "none".
 
Old November 16th, 2012, 12:06 PM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Hi,

By all means move on and ignore this but what you have said does not make sense and that bugs me? Regardless of whether this is in the form load or not, if something is stored in your setting, using my previous post should identify either way if something is there or not and deal with it?

It could be that you have added a default character by accident. I suggest deleting the setting that you already have and re-creating it, then try again.

Good luck.

Cheers,

Ian
 
Old November 16th, 2012, 12:17 PM
Authorized User
 
Join Date: Mar 2012
Posts: 59
Thanks: 2
Thanked 4 Times in 4 Posts
Default

Sorry,

I also forgot to mention that you could check your app.config file. You will have a setting called "MyNote". Just check that it is the same as the example below and all should be fine.

HTML Code:
<userSettings>
    <WindowsApplication1.My.MySettings>
        <setting name="MyNote" serializeAs="String">
            <value />
        </setting>
    </WindowsApplication1.My.MySettings>
</userSettings>
Cheers.

Ian
 
Old November 16th, 2012, 03:47 PM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[QUOTE=Ian Ryder;287861]Hi,

I suggest deleting the setting that you already have and re-creating it, then try again.


I had already tried that!
 
Old November 16th, 2012, 04:02 PM
Authorized User
 
Join Date: Jun 2012
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Ian Ryder View Post
Sorry,

I also forgot to mention that you could check your app.config file. You will have a setting called "MyNote". Just check that it is the same as the example below and all should be fine.

HTML Code:
<userSettings>
    <WindowsApplication1.My.MySettings>
        <setting name="MyNote" serializeAs="String">
            <value />
        </setting>
    </WindowsApplication1.My.MySettings>
</userSettings>
Cheers.

Ian


Ian, I also had tried this; I even went as far as adding a single space (<value>" "</value>) and it still didn't work.

I wonder if VB is adding something there between forms and or startup. My process is this:
1-SplashForm loads and checks if mynote is blank; if not it displays it.
If a note gets displayed, user can edit, delete, or keep it.
2- When the the splash screen gets closed, I do a my.settings.save and
open the main form.
3- The Mainform also provides for editing or deleting the mynote.

4- End the program.

5- Startup again, and if mynote was set to "", the my.settings shows as
a half blank " ". ???????

I need to get through with this large program, but when time permits I will go back to this issue and see if I can find the cause. If I do, I'll let you know.

Again, thanks for you help!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting With Blanks jdmcmah Excel VBA 1 August 12th, 2010 10:05 PM
Fill in the blanks voskoue Access VBA 4 January 30th, 2007 10:02 AM
blanks in Dreamweaver recordsets? fskilnik Dreamweaver (all versions) 8 June 1st, 2006 04:06 PM
Firing Blanks... ozPATT Access VBA 11 January 20th, 2006 11:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.