Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling a variable to differnt sub() 2

Status
Not open for further replies.

aburamewolf

Technical User
Oct 12, 2011
18
US
Hi I was wondering if it was possible to obtain the value of a variable that was created/used on a different sub (0

as an example:
---------------------------------------
Code:
Private Sub inotes_Enter()
Sheets("inbound").Activate

dim timestamp as string
dim cnt as long
timestamp = Format(Now, "mmm ddd dd yyyy hh:mm:ss AM/PM")

if inotes.text = "" then
inotes.text = timestamp
end if

icnt = len(inotes.text)

end sub

would it be possible to use the icnt variable? Say through:

Code:
Private Sub inoteup_click()

if inotes <> "" then
 if inotes = icnt 
MsgBox "Please Introduce A Note in Order to Save The Update", vbOKOnly, "Alert"
else
MsgBox "Saving Update", vbOKOnly, "Alert"
end if 
end if
end sub
-------------------------------------------------------
This is just a small portion of what it would do but so long as I can get inote_up(click) to use icnt as it was saved during inotes_enter() I know I can make this work.

Thanks in advance!

 

hi,

Once sub inotes finishes, the values stored in the variables vanishes.

You need to read up on SCOPE, not the kind you by at the drug store.

you inotes variable COULD be declared at the module level, rather than in a procedure.



Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

BTW, you do not "call" a variable. You "call" a procedure.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

Also, you don't have [tt]Option Explicit[/tt] at the top of your code (am I right?) because you declared [tt]
dim cnt as long[/tt]
but you use [tt]icnt[/tt] (not declared)

Unless this is just a simple sample of code.

Have fun.

---- Andy
 

let's take a closer look

inotes appears to be a TEXTBOX control.

So what is this?
Code:
if inotes <> "" then
Should it not be
Code:
if inotes.text <> "" then
Now you have already loaded inotes.text with Format(Now, "mmm ddd dd yyyy hh:mm:ss AM/PM"), or whatever you MANUALLY entered.

So why would inotes.text contain the length of what is contained in inotes.text?


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
ok so I tried multiple thing but it's still not coming up as I wanted, I'm close but not there yet, I think I was making the problem more complicated than it was.

Here's an explanation of what I'm doing.

I have a user form on which inotes once being clicked will search the "inbound" sheet for the account typed in by the user on ian.text once that's done if found it will take the notes that the account already has place two chr(10) and then time stamp it within inotes.text. So that amount of characters exactly at that point of the process is what I need, that's why I thought I needed to "call" the procedure(thanks for the correction SkipVought).

However running a simple len() on inotes and having separate internal lens() for both timestamp and the information contained on the cell ifind locates itself at, brings me close to the count, len(inotes) at the end of the code is coming up with 61 and c1 brings up a total of 57 so pretty much what I think is being skipped out is the Chr(10).

Am I compeltly wring with my logic am I overusing variables??? I apreciate all contributions.

Thanks!

Code:
Private Sub inoteup_click()

'Update Inbound information
Sheets("Inbound").Select

Dim timestamp As String
Dim cnt As Long
Dim ifind As Range
Dim xrow As Range
Dim c1 As Long
Dim cx As Long

timestamp = Format(Now, "mmm ddd dd yyyy hh:mm:ss AM/PM")
cnt = Len(timestamp)

Set ifind = Cells.find(what:=ian.Text, after:=Cells(1, 1))
If Not ifind Is Nothing Then
 cx = Len(Cells(ifind.Row, 10))
 c1 = cx + cnt
Else
 xrow = Cells.find(what:="*", SearchDirection:=xlPrevious, searchorder:=xlByRows).Row + 1
End If
If ian.Text = "" Then
    MsgBox "Please introduce an Account Number to update", vbOKOnly, "Alert"
ElseIf idispo.Text = "" Then
    MsgBox "Please choose a Disposition in order to save the update", vbOKOnly, "Alert"
ElseIf istatus.Text = "" Then
    MsgBox "Please Add A Status", vbOKOnly, "Alert"
ElseIf icontact.Text = "" Then
    MsgBox "Please Add Contact Information", vbOKOnly, "Alert"
ElseIf iterr.Text = "" Then
    MsgBox "Please Add A Territory", vbOKOnly, "Alert"
ElseIf iaccname = "" Then
    MsgBox "Please Add an Account Name/Store Number", vbOKOnly, "Alert"
ElseIf iamount = "" Then
    MsgBox "Please add amount collected, if none, please type 0", vbOKOnly, "Alert"
ElseIf inotes = "" Then
    MsgBox "Please Introduce A Note in Order to Save The Update", vbOKOnly, "Alert"
End If

If ian.Text <> "" Then
    If inotes <> "" Then
        If Len(inotes.Text) = cnt Then
            MsgBox "Please Introduce A Note in Order to Save The Update", vbOKOnly, "Alert"
        ElseIf Len(inotes.Text) = c1 Then
            MsgBox "Please Introduce A Note in Order to Save The Update", vbOKOnly, "Alert"
        End If
    End If
End If
End Sub
 



What is this count supposed to be? What is its significance?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Basically SkipVought what I want is since clicking on the notes filed auto places a time stamp the notes must contain:

if it's an already worked account:
something more than the previous notes and the time stamp.

if it's the first time the account is being worked:
something more than just the time stamp.

Hope this helps you help me.

Thanks UnsolvedCoding I will read that right now.
 

something more than ...
???
The actual length of the note and the actual length of the time stamp are know.

I STILL am totally ignorant!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Ok, so using len(vbNewLine) actually provides a value to line breaks, I will try it out with several exercises and see if this could work as a final resolution.

Thanks for link UnsolvedCoding It was of huge help
 
Ok, so using len(vbNewLine) actually provides a value (character counting-wise)to line breaks, I will try it out with several exercises and see if this could work as a final resolution.

Thanks for link UnsolvedCoding It was of huge help
 
Ok, so using len(vbNewLine) actually provides a value to line breaks, I will try it out with several exercises and see if this could work as a final resolution.

Thanks for link UnsolvedCoding It was of huge help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top