All my arrays are read-only

User avatar
stevedee
Posts: 183
Joined: Monday 20th March 2017 6:06pm

Re: All my arrays are read-only

Post by stevedee » Thursday 05th December 2019 8:51am

jornmo wrote:
Wednesday 04th December 2019 4:05pm
I believe I’ve read somewhere that Steve’s method is the recommended way, and that setting everything public should be avoided as far as possible...
Its a security thing. >>>>Ooops, see edit below

Imagine that cogier releases an update to "Killer App" to his fan base of 10 million users. He makes lblStatus Public so he can write status messages from any of the applications forms.

Someone discovers this and finds a way to write:-

lblStatus.Text = "Virus Alert - go to http:/ /hell.com/FixMe"


However, by keeping lblStatus Private, and using a routine to set the contents of lblStatus, it is possible to apply filters:-
Public Sub UpdateName(strName As String)
   
  If Instr(strName, "http") > 0 OR Instr(strName, "/") > 0 Then
	lblStatus.Text = "Please stop doing that Jornmo!"
  Else
	txtName.text = strName 
  EndIf 
   
End

*****EDIT: After writing this early this morning, I have spent a couple of hours looking for validation.

I had thought (from my VB6/Windows days) that "Publics" could be manipulated in some way from outside the program, but have failed to find any evidence to support this, or any security related issues.

So if that is the case, I can't see why Gambas Controls can't be Public, especially as they need to be qualified by their parent (e.g. Form1.txtName.Text)

User avatar
cogier
Site Admin
Posts: 395
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: All my arrays are read-only

Post by cogier » Thursday 05th December 2019 1:25pm

Imagine that cogier releases an update to "Killer App" to his fan base of 10 million users.
Imagine......

User avatar
Got2BeFree
Posts: 86
Joined: Saturday 26th November 2016 2:52am
Location: Lost

Re: All my arrays are read-only

Post by Got2BeFree » Thursday 05th December 2019 2:04pm

cogier wrote:
Thursday 05th December 2019 1:25pm
Imagine that cogier releases an update to "Killer App" to his fan base of 10 million users.
Imagine......
10 million, that's all? Must not have been a very good app! :lol:
sholzy

I'm wondering around lost in the past, not knowing where the present is.

User avatar
issboss
Posts: 27
Joined: Wednesday 16th October 2019 6:20pm
Location: Ohio, USA
Contact:

Re: All my arrays are read-only

Post by issboss » Thursday 05th December 2019 3:11pm

:D :D :D This is one of my favorite forums.

Bill
Retired 20-year USN veteran. In IT field since 1961.

cage
Posts: 47
Joined: Monday 02nd September 2019 5:47am
Location: Phoenix Arizona

Re: All my arrays are read-only

Post by cage » Thursday 05th December 2019 7:27pm

Another option is to use a module. I name mine Global so I know that I am using a global variable. You can pass variables to any form with this method without having to declare public variables.
' Gambas class file

Public Sub Form_Open()
    
    
    FMain.Center
    
    'Set the text contained in TextBox1 and TextBox2
    'from the global varibles
    TextBox1.Text = Global.Name1
    TextBox2.Text = Global.Name2
    TextBox1.SetFocus
End



Public Sub Button1_Click()

'Assign the text from TextBox1 to Global.Name1 in Global Modue
  Global.Name1 = TextBox1.Text
 'Close the main from and open the second windo 
  Me.Close
  Form2.Show


End

Public Sub Button2_Click()

Me.Close

End

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

' Gambas class file




Public Sub Form_Open()
  
   Form2.Center
   
  'Assing the value of TextBox1 through the global
  'varible Global.Name, name being the modual varible
  'in global modual.
  TextBox3.Text = Global.Name1

End

Public Sub Button1_Click()

  'Assign the contents of TextBox3 to 
  'Global.Name2 to pass it on to FMain TextBox2
  Global.Name2 = TextBox3.Text
'Reopen FMain
  FMain.Show
   
  Me.Close
  

End


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Gambas module file

'Set up a global varible to pass data between windows.
Public Name1 As String
Public Name2 As String

Just enter some text in the first textbox then click the button to open Form2. The text you entered in the textbox in FMain will be in the textbox in Form2. Enter text again in the text box in Form2 then click the button to return to FMain. Now textbox2 will contain the text you entered on Form2. It's actually a simple way to pass variables that can be accessed from any form.

User avatar
Got2BeFree
Posts: 86
Joined: Saturday 26th November 2016 2:52am
Location: Lost

Re: All my arrays are read-only

Post by Got2BeFree » Thursday 05th December 2019 9:20pm

cage wrote:
Thursday 05th December 2019 7:27pm
Another option is to use a module. I name mine Global so I know that I am using a global variable. You can pass variables to any form with this method without having to declare public variables.

Just enter some text in the first textbox then click the button to open Form2. The text you entered in the textbox in FMain will be in the textbox in Form2. Enter text again in the text box in Form2 then click the button to return to FMain. Now textbox2 will contain the text you entered on Form2. It's actually a simple way to pass variables that can be accessed from any form.
Yep, same here. Except I call mine MGlobal. :lol: Makes it really handy to have all the global variables in one place.
sholzy

I'm wondering around lost in the past, not knowing where the present is.

User avatar
issboss
Posts: 27
Joined: Wednesday 16th October 2019 6:20pm
Location: Ohio, USA
Contact:

Re: All my arrays are read-only

Post by issboss » Thursday 05th December 2019 10:18pm

I agree completely about Global. Every one of my VB programs had a Global.bas module in it. I also put my Utilities in another and the Communications (if any) in another. It was during the initial translation process I got tangled up in the intricacies of different methods for different languages. I'm pretty much out of the woods now and simply tying up loose ends. This has been an interesting thread for me.

Bill
Retired 20-year USN veteran. In IT field since 1961.

Post Reply