VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,455 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,623 people online right now. Registration is fast and FREE... Join Now!




Store Value in Label for next use

 

Store Value in Label for next use

rpcswizz

28 Apr, 2009 - 05:48 PM
Post #1

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 6



Thanked: 1 times
My Contributions
Good Day everyone!

I just want to ask to anyone of you..

Is there a way or a code that can store the value on a label without dbase?

ex. i am trying to make a auto number and every time the user open the application this will generate a number.

i am using this code

CODE

dim a as string
a=0
if a = o then
a=0
a = a + 1
label1.caption = a
else
a=a+1
label1.caption = a
end if


thanks in advance!

This post has been edited by rpcswizz: 28 Apr, 2009 - 05:53 PM

User is offlineProfile CardPM
+Quote Post


June7

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:03 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 476



Thanked: 37 times
My Contributions
Either change the caption on that label or another label and save the form with changes. Careful, all changes to form and any objects on it to that point will also be saved.
Otherwise, I say no.
User is offlineProfile CardPM
+Quote Post

rpcswizz

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:07 PM
Post #3

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 6



Thanked: 1 times
My Contributions
QUOTE(June7 @ 28 Apr, 2009 - 06:03 PM) *

Either change the caption on that label or another label and save the form with changes. Careful, all changes to form and any objects on it to that point will also be saved.
Otherwise, I say no.


but how can i change the caption of label by code that can be the new caption of the label.

P.S. Thanks for the reply
User is offlineProfile CardPM
+Quote Post

Core

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:10 PM
Post #4

Den The Developer
Group Icon

Joined: 8 Dec, 2008
Posts: 2,944



Thanked: 214 times
Dream Kudos: 900
Expert In: C#, VB.NET, .NET Framework

My Contributions
First of all, your code contains redundant pieces - why do you assign 0 to a if you later increment it by 1? Just set is as 1. Second, you rely on implicit conversion (from string to integer). If you need a variable that will contain intgers, use the Integer data type to store the values. Then. just convert that to string.

To store the current caption of the label control (if i correctly understand the task) you can write the data to a file. There are a couple of tutorials here that can help you:

http://www.dreamincode.net/forums/showtopic29575.htm
http://www.dreamincode.net/forums/showtopic97037.htm
User is offlineProfile CardPM
+Quote Post

rpcswizz

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:15 PM
Post #5

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 6



Thanked: 1 times
My Contributions
QUOTE(Core @ 28 Apr, 2009 - 06:10 PM) *

First of all, your code contains redundant pieces - why do you assign 0 to a if you later increment it by 1? Just set is as 1. Second, you rely on implicit conversion (from string to integer). If you need a variable that will contain intgers, use the Integer data type to store the values. Then. just convert that to string.

To store the current caption of the label control (if i correctly understand the task) you can write the data to a file. There are a couple of tutorials here that can help you:

http://www.dreamincode.net/forums/showtopic29575.htm
http://www.dreamincode.net/forums/showtopic97037.htm


Thanks for your compliment..
But i assign a = 0 so that when the user open for the first time the application the label will count the user as 1 that's why i increment it to 1.

but thanks for your help i will read the forums you gave.


User is offlineProfile CardPM
+Quote Post

Core

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:23 PM
Post #6

Den The Developer
Group Icon

Joined: 8 Dec, 2008
Posts: 2,944



Thanked: 214 times
Dream Kudos: 900
Expert In: C#, VB.NET, .NET Framework

My Contributions
This piece of code is completely redundant:

CODE

if a = o then
a=0
a = a + 1


It can be like this:

CODE

If A = 0 Then
A =1


Since you are incrementing the value on every launch, you can just use this:

CODE

A = A + 1


And no verification is needed.
User is offlineProfile CardPM
+Quote Post

rpcswizz

RE: Store Value In Label For Next Use

28 Apr, 2009 - 06:26 PM
Post #7

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 6



Thanked: 1 times
My Contributions
QUOTE(rpcswizz @ 28 Apr, 2009 - 06:15 PM) *

QUOTE(Core @ 28 Apr, 2009 - 06:10 PM) *

First of all, your code contains redundant pieces - why do you assign 0 to a if you later increment it by 1? Just set is as 1. Second, you rely on implicit conversion (from string to integer). If you need a variable that will contain intgers, use the Integer data type to store the values. Then. just convert that to string.

To store the current caption of the label control (if i correctly understand the task) you can write the data to a file. There are a couple of tutorials here that can help you:

http://www.dreamincode.net/forums/showtopic29575.htm
http://www.dreamincode.net/forums/showtopic97037.htm


Thanks for your compliment..
But i assign a = 0 so that when the user open for the first time the application the label will count the user as 1 that's why i increment it to 1.

but thanks for your help i will read the forums you gave.


i already check the forums you gave but that forum will save the data to a text file.. what i want to do is...

whenever the user open the application the caption on the label will increment as 1 so that i know how many users open the application.

the twist is i want to do this without using any database.. i want to change the default caption of the label that assign to properties.

QUOTE(Core @ 28 Apr, 2009 - 06:23 PM) *

This piece of code is completely redundant:

CODE

if a = o then
a=0
a = a + 1


It can be like this:

CODE

If A = 0 Then
A =1


Since you are incrementing the value on every launch, you can just use this:

CODE

A = A + 1


And no verification is needed.


okay i got your point but how can i store the value in the label?
User is offlineProfile CardPM
+Quote Post

June7

RE: Store Value In Label For Next Use

28 Apr, 2009 - 08:31 PM
Post #8

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 476



Thanked: 37 times
My Contributions
Let's say the label starts with caption of "User15"
Change it to "User16" by

CODE
Me.Label1.Caption = "User" & Mid(Me.Label1.Caption,5) + 1
Include in the Form Open event?

This post has been edited by June7: 28 Apr, 2009 - 08:35 PM
User is offlineProfile CardPM
+Quote Post

Core

RE: Store Value In Label For Next Use

28 Apr, 2009 - 08:37 PM
Post #9

Den The Developer
Group Icon

Joined: 8 Dec, 2008
Posts: 2,944



Thanked: 214 times
Dream Kudos: 900
Expert In: C#, VB.NET, .NET Framework

My Contributions
Saving the data in a file is not the same as saving in a database. You will have to store that specific value in an external file anyway (or write the data to registry).
User is offlineProfile CardPM
+Quote Post

rpcswizz

RE: Store Value In Label For Next Use

28 Apr, 2009 - 10:31 PM
Post #10

New D.I.C Head
*

Joined: 28 Apr, 2009
Posts: 6



Thanked: 1 times
My Contributions
QUOTE(June7 @ 28 Apr, 2009 - 08:31 PM) *

Let's say the label starts with caption of "User15"
Change it to "User16" by

CODE
Me.Label1.Caption = "User" & Mid(Me.Label1.Caption,5) + 1
Include in the Form Open event?


i try the code above but still when i close the application and open it again it doesn't increment.. it stay as user 16

QUOTE(Core @ 28 Apr, 2009 - 08:37 PM) *

Saving the data in a file is not the same as saving in a database. You will have to store that specific value in an external file anyway (or write the data to registry).


Yes, you're correct.. but i want to avoid saving it to an external file.. So this means that i can't do what i was thinking??

User is offlineProfile CardPM
+Quote Post

June7

RE: Store Value In Label For Next Use

29 Apr, 2009 - 08:57 AM
Post #11

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 476



Thanked: 37 times
My Contributions
Are you saving the form right after the label caption is modified?

I work in VBA for Access so sorry if I was misleading you, but I think VB6 should be able to do this. Don't know the VB6 command to save form. I took it that there was only one user of this project. If multiple users this probably won't be practical.
User is offlineProfile CardPM
+Quote Post

skailark

RE: Store Value In Label For Next Use

1 Jul, 2009 - 06:36 PM
Post #12

New D.I.C Head
*

Joined: 1 Jul, 2009
Posts: 2

i also have a similar problem like his.. i wanted to store a string value to the registry.. and it is still unclear with me how to do it.. this is what i wanna do, i have a database (Access) that has a password.. i wanted this password be also the password of my program (the admin side).. this password is at the database itself.. my problem is, how can i retrieve the password if i cant open the database?.. since the password of the database is inside of one of the tables of the database itself.. so i come up to an idea to store the string value (password) in the registry..
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:02AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month