VBAで配列のサイズを指定しないと、エラーとなる
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
2017年12月25日月曜日
2017年12月12日火曜日
C# Array
int[] a1 = new int[10]; //10 elements
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
2017年11月30日木曜日
DjangoのModel使用
1)Modelを定義
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
Django appを作成
1)Projectを作成、cloud9環境ではすでに作成されたので、不要
django-admin startproject mysite
2)appを作成
python manage.py startapp polls
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
3)Viewを作成
polls/views.py を編集
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
4)To call the view, we need to map it to a URL
polls/urls.py を作成
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
5)To point the root URLconf at the polls.urls module
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
6)DBの設定
MySQLのアクセスモジュールを追加
sudo pip3 install PyMySQL
Projectフォルダーにsettings.pyのDATABASESを変更
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9', #dbname
'USER': 'XXXXc9', #username
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
manage.pyに以下を追加
import pymysql
pymysql.install_as_MySQLdb()
7)migrate実施
python manage.py migrate
settings.pyのINSTALLED_APPSに必要なTableが作成されれば、DB設定OK
django-admin startproject mysite
2)appを作成
python manage.py startapp polls
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
3)Viewを作成
polls/views.py を編集
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
4)To call the view, we need to map it to a URL
polls/urls.py を作成
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
5)To point the root URLconf at the polls.urls module
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
6)DBの設定
MySQLのアクセスモジュールを追加
sudo pip3 install PyMySQL
Projectフォルダーにsettings.pyのDATABASESを変更
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9', #dbname
'USER': 'XXXXc9', #username
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
manage.pyに以下を追加
import pymysql
pymysql.install_as_MySQLdb()
7)migrate実施
python manage.py migrate
settings.pyのINSTALLED_APPSに必要なTableが作成されれば、DB設定OK
2017年10月26日木曜日
cloud9でpython3/djangoを設定
django projectの設定(歯車)から、python2->3にしてから以下を実施
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.4 /usr/bin/python ->ここ3.5を設定したら、djangoが認識してくれなかったとりあえず3.4にした
sudo pip3 install django
以下のコマンドでバージョン確認
python -V
python -m django --version
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.4 /usr/bin/python ->ここ3.5を設定したら、djangoが認識してくれなかったとりあえず3.4にした
sudo pip3 install django
以下のコマンドでバージョン確認
python -V
python -m django --version
2017年10月6日金曜日
macにphpmyadminをインストール
brew install phpmyadmin
sudo vi /etc/apache2/httpd.conf で以下の設定を最後に追加
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
sudo apachectl restart
参考:https://soarcode.jp/posts/55
登録:
投稿 (Atom)