Methods of Declaring VBA Variables

In this article, we will be talking about Declaring VBA Variables. Variables are essential elements of programming. Using and managing variables are one of the musts while creating a project. I will try my best to tell it as simple as possible. Reminder: You can find other articles about VBA on our blog. 👍🏻

 

About Declaring VBA Variables

Variables are usually used to store a data and use it when necessary. They are usually separated into two classes. Global variables and Local variables. Global variables can be used by all the functions of the program, but the local variables are used by the functions that have declared them.

It can be called back, reassigned or fixed during the execution of a procedure, function or module.
Declaring a variable will enable you to indicate the names of the variable you’ll use and the data type the variable will contain.

For example, if Result = 10, the variable Result can be declared as Integer Whole Number .

We usually name the variables in a short and easily remembered way. The most frequently used variable names are one character names like i, a, n, x ,y ,z, s so that it is easy to write in the code. If the variable name is a name that you can remember while using in the code, the probability of making a mistake while writing the code decreases.

Now we can move on to the declaring part.

 

The syntax concerning declaring variables is usually like this.
Dim variable_name [(stringsize)] As type
Public variable_name[(stringsize)] As type
Static variable_name[(stringsize)] As type

 

Along side this general declaring, the declaring methods below can be used as well.

  1. Declaring with Dim
  2. Declaring with Data Indicators (Abbreviations)
  3. Declaring with DEF

Declaring with Dim

It is the most known and used VBA Variable Declaring method.

We indicated the syntax Syntax below. Let’s make it clear with a few examples. Let’s say that we will declare a variable named row to use in the rows (cells) in the A column. Since the row numbers are whole numbers, we can used one of the whole number types we’ve indicated in our Data Types article. It would be better to use the variable data type depending on the row number we’ll get controlled or the maximum number that can be in the cell.

As well as we can use as Number or Whole Number, we have 3 basic variable data types: ByteInteger and Long. If the number we’ll assign to the row variable is 255 or less, then we can use the Byte variable data type. If the number we’ll assign to the row variable is between –32767 and+32768, then we can use the Integer variable data type. If it can be a bigger whole number, then we should use the Long variable data type. If a bigger number than what the variable can contain is sent, that the Overflow error occurs. And if a text data is sent to a variable that was determined as number, Type Mismatch error occurs.

 

Let’s give a few examples of declaring variables with Dim:

Sub PEAKUP()
    Dim row As Long
    Dim column As Byte
    Dim text As String
    Dim start As Date
    Dim money As Currency
    Dim object As Object
    row = 15
    column = 5
    text = "Excel Turkey Forum"
    start = "24.06.2018"
    money = 300
    Set object= ActiveSheet
End Sub

We can write each variable one by one in different rows like that, but we also can write them side by side like this. We just need to put Dim in the beginning and put a comma between each variable.

Sub PEAKUP()
    Dim row As Long, column As Byte, text As String
    Dim start As Date, money As Currency, object As Object
End Sub

We need to be careful about this here: Some users make a mistake and declare incorrectly.

If you write the code I gave above like this one below, I mean if you start with Dim and think that you’ve declared the first variable and not declare the other variables with the suitable variable data types. Since in the “column”, “text” variable the data type is not stated, Byte and String are not indicated but Variant is -which is undefined data type. Since in the first variable I’ve declared with Dim, you declare the data type in the first variable. So, it doesn’t mean that you declare the next variables as well. You need to state the data type of each variable one by one.

 

Declaring with Data Identifiers (Abbreviations)

Abbreviations 

They are also known as Type Indication suffixes.
They are not used much but they help to save in codes.
It is also possible to tell a variable type by adding a special character to the end of the variable name in VBA.

Dim number% 'Integer
Dim longnumber& 'Long
Dim sum! 'Single
Dim subtotal# 'Double
Dim payment@ 'Currency
Dim name$ 'String
Dim longestnumber^ ' 64 bit LongLong

 

Data Type Abbreviation Characters

VBA

, as a fast way of declaring data type, lets you add a character in the name of a variable.
This method shouldn’t be used to declare variables and it can be used for retrospective purposes only.
The row below will declare a Double data type and a variable.

Dim dDouble#

But it is better for this row to be declared with the “As” keyword.
Dim dDouble As Double

 

Data Type Abbreviation/ Suffixes

If you you abbreviations, you don’t have to declare the type.
If you use the % expression, you don’t need to write “As Integer”.
These abbreviations can be helpful to get available information to Variants.

For example: count =10#

 

 

Declaring with DEF

We can declare our variables with different methods like we mentioned, one of these methods is declaring with DEF.
This declaration is usually done free from the procedure at the top of the code window.
We can abbreviate and declare the data type we use as variable like below.
The letter that comes after Def+Type indicated that the variables starting with that letter belong to that type.

def ile değişken tanımlama tablosu

Let’s see an example that shows the difference between declaring with Def and Dim.

First, let’s declare our variables like this with Dim.

Sub PEAKUP()
    Dim row As Integer, column As Integer
    Dim text As String, letter As String, word As String
    Dim date As Date, start As Date
    Dim number As Double, price As Double
    row= 10
    column= 5
    text = "PEAKUP"
    letter = "E"
    word = "Book"
    date = "24.06.2018"
    start = "14.12.1980"
    number = 1453.48
    price = 5647.15
End Sub

Now, let’s do the same declaration with Def.

DefInt R
DefStr L, W, T
DefDate S, D
DefDbl P, N
Sub PEAKUP()
    row = 10
    column = 5
    text = "PEAKUP"
    letter = "E"
    word = "Book"
    date = "24.06.2018"
    start = "14.12.1980"
    number = 1453.48
    price = 5647.15
End Sub

As you see, we got to indicate the type by using the initials and declare the variables. At this point, you want the variable declarations not to take too much space and be seen in less rows. As indicated below, you can write the Def rows in a row next to one other with a colon (:).

DefInt R: DefStr L, W, T: DefDate S, D: DefDbl P, N
Sub PEAKUP()
    row = 10
    column = 5
    text = "PEAKUP"
    letter = "E"
    word = "Book"
    date = "24.06.2018"
    start = "14.12.1980"
    number = 1453.48
    price = 5647.15
End Sub

By the way, you can easily follow and evaluate the names, values and types of all variables from Locals Window.

def ile değişken tanılamayı locals windowda görüntüleme

 

You can take a look at the Microsoft Docs page for more information.

See you in other articles, bye.🙋🏻‍♂️
You can share this post with your friends and get them informed as well. 👍🏻

Variable Types

Each object or property we use in Power Apps can be used as a variable. For example, we can set the value of a TextBox as TextBox1.Text and this way, it is defined as a variable that has a text value and that can be interfered by the users. All the values like the color of an object, the text, borders can be used. From this point of view, we can see all the objects as variables. You can take a look here to read other article concerning this topic.

Even though every object can be used as a variable, there are real functions designed to be a variable. These functions that are experts in assigning an using variables are analyzed under 3 categories for Power Apps. They are used in more dynamic actions like calculating a value in an increasing or decreasing way, rather than a static Label moving data between pages.

Power Apps Variable Types

1-General Variables:

Set

  • It’s a global/general variable, can be applied from all the screens of the app.
  • It can be created and applied anywhere in the app.
  • It can hold different data types like Numbers, Text string, Boole, Record and Table.
  • Set(variable_name; value)

2-Context Variables:

UpdateContext

  • they can be applied from one screen only.
  • a single value, a record, a table, an object reference, any result from a formula
  • UpdateContext({variable_name : value })

3-Collection: 

Collect & ClearCollect

  • Holds tables that can be created and applied anywhere in the applications.
  • Saved in the local device to be used later.
  • Different data can be enter based on columns or rows in a table.
  • Every time collect is created, writes the data on top of each other.
  • ClearCollect deletes an existing table and recreates it from scratch every time.
  • Collect( table name ;{column1: “value1” ; column2: “value2”; column3: “value3” ;…})
  • Collect( table name ;{column1: “value1” ; column2: “value2”}; {column1: “value1” ; column3: “value3”} ; {…})

You can click here to take a look at the other article concerning the usage of collections.

Date, Number and Text Filters with Custom Filters

Excel is a product that appeals to every occupational group, and facilitates life with a lot of beneficial features and formulas. There are basic actions that everyone knows and uses like Filter and Sort. We will analyze the Date, Number and Text filters in this article.

It is possible to analyze the data by choosing it on checkbox with the standard use of the filter feature. But choosing with the checkbox wouldn’t make any sense when you need to detect a certain data or date range or period in a table. Because, this action can mean analyzing the data one-by-one.

For example, what should we do to see the sales of last month in the sales table? How do we detect the products which have a price between 30 000 and 50 000? How do we analyze next week’s plans in the 1 year plan table?

Custom Filters come into the play in this case.

Date, Number and Text Filters

You need to add a Filter to use custom filters. Filter shortcut is CTRL+ SHIFT + L.

You can quickly apply custom filters with the available options like this month, last week, next quarter, yesterday in the date column.

You can choose This months from the date filter options and display like below.

We see the action This Month filter takes with the Custom Filter option.

You can execute actions for special dates or date ranges you determine with the Custom Automatic Filter window that pops open. You can click on the calendar icon on the right and choose a date.

Text Filters

You can filter with the options like Begins With, Ends With, Does Not Equal within the Text filters in order to make custom searches. Hence, you can filter the words that end with a specific word with the Ends With option.

After you choose Ends With, you can type a into the windows that opens and detect the Sales Regions that end with a.

There are a lot of options to enable customizing the search like equals, does not equal, starts with, does not start with, contains, does not contain. It is the same for Number filters. Numbers should be written directly without decimal points.

You can choose the Number Filter Between in the Sales column and apply a filter to the values between 30000 and 45000 like below.

You can click here to see the other MS Office articles.

Authorization with Department Control

You can enable interactive flow or do visual actions by creating rules in the application screen. Depending on the situation in the application scenario, you can connect objects or actions to department, user mail, location, title, marital status or user choice in multiple-choice actions.

Usually hide, show, freeze, open to edit or change color, location, size actions are done for the determined objects. You can apply all these controls in all application scenarios easily and flexibly.

Users whose department is HR will see the HR button that enables them to open the management and confirmation screen of HR.

It is better to do these actions step by step and in pieces while doing these controls. Like I mentioned in my previous article, the formula evaluations should be controlled in different labels and should be named depending on the outcome.

We will test the user department first in the example below.

Department Detection for the Existing User

We will use the Office365Users.MyProfile() formula that lets us get the existing login info of the user that opens the app for this action.

We will write the formula below in a label we named lbl_user_departmant and get the department information.

Office365Users.MyProfile().Department 

Is The Detected Department HR?

We will write the formula below into a label we named lbl_is_user_department_hr and check if the existing user is in the Human Resources department. If the user is in the HR, we will get the outcome as 1, if not; 0.

 

If the existing user is HR, what actions will be on the screen?

The Visible option of HR button will change depending on the 1/0 values that will come from the label named lbl_is_user_department_hr.

This way, the button will be showed and hidden depending on the department.

If(lbl_is_user_department_hr.Text=Value(1);true;false) 

Control Formulas

The labels named lbl_user_departmant and lbl_is_user_department_hr should be moved to the formula screen so that it is easier to revise them later. Click here to take a look at the article about creating a formula screen and its importance.

You can read about the details of the functions that are used to get user information through Office 365 here.

Similar Examples

You can do similar control with the same steps while filling a form prepared for personnel that consists of personal information like Name, Surname, ID Number, Gender, Date of Birth, Marital Status, Military Service Status.

When the gender is marked as Female, the military service status will be hidden (Visible) since it won’t be filled or it can be frozen (DisplayMode).

When the marital status is marked as single, the fields concerning spouse and children can be hidden (Visible) since they won’t be filled or they can be frozen (DisplayMode).

You can click here for other Power Apps articles.

Evolution of Leadership

We all saw during this new remote working and work order that came to our lives with the pandemic and we foresee to be permanent, that different characteristics of management has come to the forefront. These characteristics are very important in continuing the workflow non-stop and increasing employee loyalty and keeping the personnel loss minimum. So, let’s go over what these characteristics are.

Leaders need to assure the team that they trust them and believe that they will do their best. The “nosy parker” leaders that always keep the workers in sight have come to an end with the pandemic. Of course, explaining this with the pandemic only would be insufficient. We all foresaw that with the Z generation entering the work like actively, the management style would be changing. From now on, work processes will keep going with mutual trust, respect and open communication. It is important to mention that performance evaluation will be outcome oriented. In this new work order, leaders who reassure the employees, who can openly communicate, who create solutions to employees’ problems and who have a strong planning aspect will be prominent.

With the new era, management of teams that work in remote places restrict managing everyone one by one. Thus, the era of leaders who take the team’s professions and abilities seriously, who trust and take their ideas seriously and who can assure the teams with the “we are a team” feeling begins.

We will observe that the leaders who keep the employee motivation in the forefront will be working more productively. It is important to know the team, their characteristics and how they get motivated. Especially with the remote working era, we might have to create a different working standard for each person. You, day by day, will realize the importance of leaders who do this planning.

Alongside all this, the value of leaders that plan the work and time management efficiently, follow team’s workflow and guide when necessary will increase. Yes, everybody has their individual responsibilities but it is important to keep in mind that leaders have a bit more.

So, how much of these characteristics do you have?

MS Forms Integrated with All Platforms

Integrated Platforms

You can use Forms integrated with products like Teams, PowerPoint, Sway, Stream or your website. With MS Forms, preparing and distributing forms is very practical. You can distribute the prepared polls with a link on a user-base or publish them in digital platforms.  It can work integrated with web sites, presentations, journals and communication platforms.

Teams & MS Forms

It stands out with the document sharing and co-authoring options that help to maintain a high-level communication. You can use Power BI reports, Power Apps mobile apps and hundreds of apps integrated with Teams. Also, you can use MS Forms polls within Teams.

TEAM: Polls can be added to tabs in teams and be shared from a center and access can be controlled.

 

CHAT: Similarly, you can add polls into chats as well. You can create a connection with the respond link of the poll with the add a Web Site option.

Take a look at this link for the details of Teams&Forms integration.

Sway & MS Forms

You can run your internal or external communication process like mailing, journal, presentation, announcements and celebration with Sway.

You can view polls with embedded code in Sway journals. This way, you can both share announcements with your personnel or customers and get feedback.

You can use this system in your events. You can make the event details like topic, content, duration and location a presentation with Sway and simultaneously collect feedback of participation.

And when the users approve the participation to your from,  you can automatically send an automatic meeting invitation with Power Automate.

Take a look at this link for the details of Sway&Forms integration.

 

PowerPoint & MS Forms

You can get responses from people you’ve sent your presentation to by adding MS Forms to PowerPoint presentations.

This way, the person who receives your presentation can respond your poll without changing to another screen.

You can create an education and exam system with this feature. You can talk about a certain topic in the presentation and make the users come across a test right at the end.

You can collect poll/test responds by adding them separately at the end of each part.

Take a look at the link for the details of PowerPoint & Forms integration.

Share

The poll link, QR code, embedded code and mail options are location under the Share button in the editing screen of the form.

 

You can click here to take a look at our other articles.

Remote Working and Digital Communication Summit

Our “Remote Working and Communication Summit” event where we talked about how to work more efficiently with online systems and did demos with the CIO Turkey team took place through a live event on Microsoft Teams.

Tracking the communication and workflow from one center, making everyone receive the announcements and information at the same time and speed enable unity of internal and external communication. Being able to organize and record live events and trainings within MS Teams, considering the pandemic, enable you to execute the face-to-face interviews online. You can make phone calls and have conferences and access a limitless number of users. Hence, you start digitizing your work processes through a more secure and easier platform. In this period of time where time and productivity is this valuable, MS Teams minimizes the time loss caused by communication flaws.

With CIO Turkey, we analyzed Microsoft Teams that enables migrating work places to online with the work life changing to remote working, maintaining conferences, events or meetings doesn’t matter where and its solutions that makes the work processes easier .

We kindly thank everyone who participated in the “Remote Working and Digital Communication Summit.”

FIELDVALUE Function

In this article, we will be informing you about the FIELDVALUE Function used with the Linked Data Types. You can use the FIELDVALUE function to retrieve field data from linked data types like the Stocks or Geography data types.

bağlantılı veri türleri

There are easier methods for writing formulas that reference data types, so the FIELDVALUE function should be used mainly for creating conditional calculations based on linked data types.

 

SYNTAX

fieldvalue fonksiyonu söz dizimi

This function requires two arguments.
It is necessary to enter both of these arguments.

There are these independent variables in the syntax of the FIELDVALUE function:

  • value– Function returns all matching fields(s) from the linked data type specified in the value argument.
  • field_name– The name or names of the fields you would like to extract from the linked data type.

Description

  • The FIELDVALUE function returns all matching fields(s) from the linked data type specified in the value argument.

  • The FIELDVALUE function belongs to the Lookup & Reference family of functions.

 

Examples

In the following basic example, the formula =FIELDVALUE(A2,”Area”) extracts the Area field from the geography data type for Turkey.

fieldvalue fonksiyonu örnek

Let’s list the data in the related field depending on the dynamic field choice about cities.

fieldvalue fonksiyonu örnek

 

Remarks

If you try to retrieve data from a non-existent data type field, the FIELDVALUE function will return the #FIELD! error. For instance, you might have entered “Field“, when the actual data type field is named “Area“. Double-check your formula to make sure you’re using a valid field name. If you want to display a list of field names for a record, select the cell for the record, and press Ctrl+Shift+F2 .

You can get more information on Microsoft Support.

See you in other articles, bye. 🙋🏻‍♂️
You can share this post with your friends and help them get informed as well.👍🏻

Capital – Fast Start Up

“WE ARE ACHIEVING OUR GOAL STEP BY STEP”

PEAKUP CEO Ahmet Toprakçı stated that they are preparing to open an office in the USA after UK and that they are among the fastest developing technology companies and added: “Our goal is to become a global company. We are achieving this step by step.”

PEAKUP helped over 600 thousand end users to migrate to cloud technologies as of today. They have over 700 customers in Europe, Middle East and Africa. PEAKUP was among the first 50 companies 3 years in a row in Deloitte Technology 2019 Fast 50 Turkey Program that determines the fastest growing 50 technology companies.

Ahmet Toprakçı, the founder and CEO of this 100% national capital company that exports technology abroad, highlights that their goal is to maintain the growth acceleration they’ve obtained. Toprakçı explained that they’ve developed with their own resource and that they don’t need funds and explains what they do like this:

“I HAVE THREE TEXTBOOKS”

“I have completed the Electrical Engineering major in Istanbul Technical University. And then, I did my masters degree in the same university. I had an experience of 6 years in corporate life before establishing my own business. I worked as a system manager in ITU Information Technology Department, as a lecturer, consultant and manager in Bilge Adam IT Academy.

In 2012, with cloud technologies entering the corporate world, I couldn’t ignore this trend and established my enterprise. Now, we have PEAKUP HR and London-based PEAKUP Technologies UK companies under the roof of PEAKUP technologies. Also, I have 3 textbooks that are used in lectures in universities.

WE’VE OPENED AN OFFICE IN UK

We hit the road with a very low capital. We didn’t get any support from VC or informal investors. Our model was “Bootstrapping”. We grew with our own resources. Opening an office in London as an 100% national capital technology company and being a Turkish company that exports technology to the world was one of the most important milestones for us.

We also create local technology solutions in our R&D center. We have a lot of projects that we carry out with the Scientific and Technological Research Council of Turkey (TÜBİTAK) and the Industrial Ministry. Today, we are among the first 500 IT companies and on a non-sector base among the first 250 companies that invest in R&D the most. Also, we have been among the Deloitte Technology Fast 50 3 years in a row.

“WE ARE GETTING PREPARED FOR PATENTS”

My most important goal is the turn our products into a strong brand in international competition and to be a global company. In this direction, we are working on getting the patents of our products and apply our international marketing technology. We are achieving our goal step by step.

After UK, we will be opening our US office soon. On the other hand, we want to show that a global technology brand can come from Turkey and inspire people. We foresee an increase of 15-20% in our workforce plan. Business intelligence, IoT, mobile and web based software will be main areas of our recruitment.”

 

IoT platform Nova will pioneer contact-free working

PEAKUP aims to pave the way for contact-free work in offices and factories by popularizing the usage of Nova, the IoT platfrom they’ve developed.

PEAKUP has developed a platform to make workers that are back to working continue their work contact-free. It is sated that Nova, 100% local IoT platform that was developed by Turkish engineers in PEAKUP technology labs, enables working contact-free in a lot of areas. This platform that detects if someone’s temperature goes up has a lot of features that enable controlling lights and ac without any contact as well as blocking the entrance of someone who doesn’t need to come to the office.

PEAKUP COO Kadircan Toprakçı stated that Nova is a smart management platform. He highlighted that they have a lot of different control scenarios. And expressed that they believe the platform will especially be important during the coronavirus pandemic to decrease contagion through contact. Toprakçı said that there is a perception as “IoT apps are usually products that SMEs cannot access”. He said they want to popularize this platform among SMEs too with an affordable price. Toprakçı said: “Even if it’s just a studio, how much the machines work and their efficiency is calculated with a simple app. With this platform, the efficiency of operators can be calculated as well.”

“Detects and reports the risks”

Toprakçı mentioned that Nova has other smart features than turning on and off through a mobile app. He continued: “It has automatic control mechanisms like turning the lights on when it is dark inside or turning the ac on when the carbon dioxide level is too high. It warns the overcrowded areas by detecting the number of people per square meter. It has a determining role in putting just the people in the risk group into quarantine rather than shutting down the whole office in case of a risk. Analyzed and reports the people who was contacted by the risky person”. Toprakçı stated that with this platform, you can take someone’s temperature contact-free as well and a person with a risk will not be let in and said: “If someone’s temperature goes up during the day, it will be detected with the heat detector and warning and guidance systems will activate by detecting where that person walked around in the office and who he/she had contact with.”

Toprakçı mentioned that it also enables to measure efficiency with artificial intelligence. He added:” It can detect workers that always take a break together. You can measure the time people spend outside. It can warn when a personnel goes into a restricted area in terms of occupational health and security. When someone’s temperature goes up entrance to the areas that person contacted can be blocked. Even before knowing if that person is sick or not.”

Nova was developed with open innovation

Kadircan Toprakçı said that Nova, that is the product of around a 2 year work, was developed with the open innovation method with their customers and said: “While we were developing, we learned this: For example, waking up chicken during the night is important in terms of efficiency. This platform enables you to wake your chicken up whenever you want with sensors.”